Bulk.insert()

On this page本页内容

Tip提示

Starting in version 3.2, MongoDB also provides the db.collection.bulkWrite() method for performing bulk write operations.从3.2版开始,MongoDB还提供了db.collection.bulkWrite()方法来执行批量写入操作。

Description描述

Bulk.insert(<document>)

Adds an insert operation to a bulk operations list.将插入操作添加到批量操作列表。

Bulk.insert() accepts the following parameter:接受以下参数:

Parameter参数Type类型Description描述
docdocumentDocument to insert. 要插入的文档。The size of the document must be less than or equal to the maximum BSON document size.文档大小必须小于或等于最大BSON文档大小

Example示例

The following initializes a Bulk() operations builder for the items collection and adds a series of insert operations to add multiple documents:以下内容初始化items集合的Bulk()操作生成器,并添加一系列插入操作以添加多个文档:

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();
←  Bulk.getOperations()Bulk.tojson() →