Docs HomeMongoDB Manual

Bulk.toJSON()

On this page本页内容

Bulk.toJSON()

Returns a JSON document that contains the number of operations and batches in the Bulk() object.返回一个JSON文档,该文档包含Bulk()对象中的操作数和批处理数。

Example实例

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.下面初始化items集合上的Bulk()操作生成器,添加一系列写操作,并调用Bulk.toJSON()对象。

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.toJSON();

The Bulk.toJSON() returns the following JSON documentBulk.toJSON()返回以下JSON文档

{
acknowledged: true,
insertedCount: 2,
insertedIds: [
{ index: 0, _id: ObjectId("627bf77e5e19ff3518448887") },
{ index: 1, _id: ObjectId("627bf77e5e19ff3518448888") }
],
matchedCount: 0,
modifiedCount: 0,
deletedCount: 0,
upsertedCount: 0,
upsertedIds: []
}
Tip

See also: 另请参阅:

Bulk()