Bulk.insert()

Tip

Starting in version 3.2, MongoDB also provides thedb.collection.bulkWrite() method for performing bulkwrite operations.

Description

  • Bulk.insert()

New in version 2.6.

Adds an insert operation to a bulk operations list.

Bulk.insert() accepts the following parameter:

ParameterTypeDescriptiondocdocumentDocument to insert. The size of the document must be less than orequal to the maximum BSON document size.

Example

The following initializes a Bulk() operations builder for theitems collection and adds a series of insert operations to addmultiple documents:

  1. var bulk = db.items.initializeUnorderedBulkOp();
  2. bulk.insert( { item: "abc123", defaultQty: 100, status: "A", points: 100 } );
  3. bulk.insert( { item: "ijk123", defaultQty: 200, status: "A", points: 200 } );
  4. bulk.insert( { item: "mop123", defaultQty: 0, status: "P", points: 0 } );
  5. bulk.execute();

See also