Bulk Write


The code snippets on this page demonstrate how to perform a bulk write operation with the collection.bulkWrite() function.


Data Lake data sources do not support write operations.

Snippet Setup

To use a code snippet in a function, you must first instantiate a MongoDB collection handle:

exports = function() {
  const mongodb ="mongodb-atlas");
  const itemsCollection = mongodb.db("store").collection("items");
  const purchasesCollection = mongodb.db("store").collection("purchases");
  // ... paste snippet here ...


The following example inserts two documents into the store.purchases collection:

exports = async function(arg){
    const doc1 = { "name": "velvet elvis", "quantity": 20, "reviews": [] };
    const doc2 = { "name": "mock turtleneck",  "quantity": 30, "reviews": [] };

    var collection ="mongodb-atlas")

    return await collection.bulkWrite(
        [{ insertOne: doc1}, { insertOne: doc2}],
←   Transactions Query Roles  →