sincecutoff.com
← all changes

mongosh shell API adds Session.bulkWrite()

Introduced 2026-06-25 · score 0.90

HOW TO USE IT

When repository code needs to submit multiple MongoDB writes through a session, call `Session.bulkWrite(operations, options)` with an array of write-operation documents. The operation requires MongoDB 8.0 or later.

const session = db.getMongo().startSession(); session.bulkWrite([ { namespace: "<db>.<collection>", name: "insertOne", document: { <field>: <value> } }, { namespace: "<db>.<collection>", name: "updateOne", filter: { <field>: <value> }, update: { $set: { <field>: <value> } } } ]);

WHY THIS HELPS

When implementing repository code that needs to submit multiple MongoDB writes through a mongosh session, use the shell API bulk write method.

REQUIREMENTS AND LIMITATIONS

  • Version: v2.9.0
  • operations (required): Array of write-operation documents. Each specifies a namespace, operation name, and operation-specific fields. Supported operations: insertOne, replaceOne, updateOne, updateMany, deleteOne, deleteMany.
  • options: Options document; all documented sub-keys are optional: `ordered` (default true; stop at first error when true), `verboseResults` (default false), `bypassDocumentValidation` (default false), and `let` (document of values available as aggregation variables). No mutual exclusions are documented.
  • namespace (required): Operation document key: database and collection for the write, in `<db>.<collection>` form.
  • name (required): Operation document key: operation name, such as `insertOne` or `updateOne`.
  • document (required): For `insertOne`, the document to insert.
  • filter (required): For update, replace, and delete operations, the document selector for matching documents.
  • update (required): For `updateOne` or `updateMany`, the update document or array of update documents.
  • Prerequisite: Use a MongoDB 8.0 or later deployment. Create the session with `db.getMongo().startSession()` before calling the method.

FIRST-PARTY EVIDENCE

Check the installed version and the source before using it. Entry JSON

Report a problem with this card