Docs Menu
Docs Home
/
MongoDB Manual
/ / /

Bulk.tojson()

On this page

  • Example
Bulk.tojson()

Returns 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.tojson() 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" } ).removeOne();
bulk.tojson();

The Bulk.tojson() returns the following JSON document

{ "nInsertOps" : 2, "nUpdateOps" : 0, "nRemoveOps" : 1, "nBatches" : 2 }

Tip

See also:

Back

Bulk.insert()

On this page