Docs Menu

Bulk.toString()

On this page

  • Example
Bulk.toString()

Returns as a string a JSON document that contains the number of operations and batches in the Bulk() object.

The following initializes a Bulk() operations builder on the items collection, adds a series of write operations, and calls Bulk.toString() on the bulk builder object.

var bulk = db.items.initializeOrderedBulkOp();
bulk.insert( { item: "abc123", status: "A", defaultQty: 500, points: 5 } );
bulk.insert( { item: "ijk123", status: "A", defaultQty: 100, points: 10 } );
bulk.find( { status: "D" } ).deleteOne();
bulk.toString();
bulk.execute()

The Bulk.toString() returns the following JSON document

{
acknowledged: true,
insertedCount: 2,
insertedIds: [
{ index: 0, _id: ObjectId("627bf4f95e19ff3518448883") },
{ index: 1, _id: ObjectId("627bf4f95e19ff3518448884") }
],
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
upsertedCount: 0,
upsertedIds: []
}
Tip
See also:
←  Bulk.toJSON()User Management Methods →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.