collection.bulkWrite()¶
Definition¶
collection.bulkWrite()
¶
Bulk insert/update/delete multiple documents in a single collection with one
call. Within the bulkWrite()
function, you can specify one or more of
the following write operations:
- insertOne
- updateOne
- updateMany
- deleteOne
- deleteMany
- replaceOne
Note
The bulkWrite()
function operates on a single collection.
Usage¶
Example¶
To call the collection.bulkWrite()
action from a
Function, get a collection handle with
database.collection()
then call the handle's
bulkWrite()
function.
exports = async function(arg){ const doc1 = { "name": "velvet elvis", "quantity": 20, "reviews": [] }; const doc2 = { "name": "mock turtleneck", "quantity": 30, "reviews": [] }; var collection = context.services.get("mongodb-atlas") .db("store") .collection("purchases"); return await collection.bulkWrite( [{ insertOne: doc1}, { insertOne: doc2}], {ordered:true}); };
Parameters¶
The collection.bulkWrite()
action has the following form:
bulkWrite(operations, options)
Parameter | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
operations | An array of bulkWrite operations to perform. Examples of supported operations include the following:
| ||||||||||||
options | Optional. An object that specifies the optional settings. Valid options are:
|
Return Value¶
The collection.bulkWrite()
function returns a Promise that resolves to null
.
Give Feedback