Docs Menu

Bulk.insert()

On this page

  • Description
  • Example
Tip
Bulk.insert(<document>)

Adds an insert operation to a bulk operations list.

Bulk.insert() accepts the following parameter:

Parameter
Type
Description
doc
document
Document to insert. The size of the document must be less than or equal to the maximum BSON document size.

The following initializes a Bulk() operations builder for the items collection and adds a series of insert operations to add multiple documents:

var bulk = db.items.initializeUnorderedBulkOp();
bulk.insert( { item: "abc123", defaultQty: 100, status: "A", points: 100 } );
bulk.insert( { item: "ijk123", defaultQty: 200, status: "A", points: 200 } );
bulk.insert( { item: "mop123", defaultQty: 0, status: "P", points: 0 } );
bulk.execute();
Tip
See also:

On this page

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.