Docs HomeMongoDB Manual

db.collection.bulkWrite()

Definition定义

db.collection.bulkWrite()
Important

mongosh Method

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

Performs multiple write operations with controls for order of execution.使用控制执行顺序的控件执行多个写入操作。

db.collection.bulkWrite() has the following syntax:具有以下语法:

db.collection.bulkWrite(
[ <operation 1>, <operation 2>, ... ],
{
writeConcern : <document>,
ordered : <boolean>
}
)
Parameter参数Type类型Description描述
operationsarrayAn array of bulkWrite() write operations.bulkWrite()写入操作的数组。
Valid operations are: 有效操作包括:

See Write Operations for usage of each operation.有关每个操作的用法,请参阅写入操作

writeConcerndocumentOptional.可选的。A document expressing the write concern. Omit to use the default write concern.表示写入关注的文档。忽略使用默认的写入关注。
Do not explicitly set the write concern for the operation if run in a transaction. 如果在事务中运行,请不要显式设置操作的写入关注。To use write concern with transactions, see Transactions and Write Concern. 要在事务中使用写入关注,请参阅事务和写入关注
orderedbooleanOptional.可选的。A boolean specifying whether the mongod instance should perform an ordered or unordered operation execution. 一个布尔值,指定mongod实例应该执行有序操作还是无序操作。Defaults to true.默认为true
See Execution of Operations 请参阅操作执行
Returns:返回值:
  • A boolean acknowledged as true if the operation ran with write concern or false if write concern was disabled.如果操作在有写入关注的情况下运行,则布尔值acknowledgedtrue;如果写入关注被禁用,则布尔值acknowledgedfalse
  • A count for each write operation.每个写入操作的计数。
  • An array containing an _id for each successfully inserted or upserted documents.一个数组,其中包含每个成功插入或打乱排序的文档的_id

Behavior行为

bulkWrite() takes an array of write operations and executes each of them. 获取一组写操作并执行其中的每一个。By default operations are executed in order. 默认情况下,操作按顺序执行。See Execution of Operations for controlling the order of write operation execution.有关控制写入操作执行顺序的信息,请参阅操作执行

Write Operations写入操作

insertOne

Inserts a single document into the collection.在集合中插入单个文档。

db.collection.bulkWrite( [
{ insertOne : { "document" : <document> } }
] )

See db.collection.insertOne().请参见数据库集合db.collection.insertOne()

updateOne and updateMany

updateOne updates a single document in the collection that matches the filter. 更新集合中与筛选器匹配的单个文档。If multiple documents match, updateOne will update the first matching document only.如果多个文档匹配,updateOne将只更新第一个匹配的文档。

db.collection.bulkWrite( [
{ updateOne :
{
"filter": <document>,
"update": <document or pipeline>, // Changed in 4.2
"upsert": <boolean>,
"collation": <document>, // Available starting in 3.4
"arrayFilters": [ <filterdocument1>, ... ], // Available starting in 3.6
"hint": <document|string> // Available starting in 4.2.1
}
}
] )

updateMany updates all documents in the collection that match the filter.updateMany更新集合中与筛选器匹配的所有文档。

db.collection.bulkWrite( [
{ updateMany :
{
"filter" : <document>,
"update" : <document or pipeline>, // Changed in MongoDB 4.2
"upsert" : <boolean>,
"collation": <document>, // Available starting in 3.4
"arrayFilters": [ <filterdocument1>, ... ], // Available starting in 3.6
"hint": <document|string> // Available starting in 4.2.1
}
}
] )
Field字段Notes备注
filterThe selection criteria for the update. 更新的选择条件。The same query selectors as in the db.collection.find() method are available.可以使用与db.collection.find()方法中相同的查询选择器
updateThe update operation to perform. 要执行的更新操作。Can specify either: 可以指定以下任一项:
upsertOptional.可选的。A boolean to indicate whether to perform an upsert.指示是否执行追加销售的布尔值。
By default, upsert is false. 默认情况下,upsertfalse
arrayFiltersOptional.可选的。An array of filter documents that determine which array elements to modify for an update operation on an array field.一组筛选文档,用于确定要为数组字段的更新操作修改哪些数组元素。
collationOptional.可选的。Specifies the collation to use for the operation.指定要用于操作的排序规则
hintOptional.可选的。The index to use to support the update filter. 用于支持更新filter索引If you specify an index that does not exist, the operation errors. 如果指定的索引不存在,则操作将出错。
New in version 4.2.1. 4.2.1版新增。

For details, see db.collection.updateOne() and db.collection.updateMany().有关详细信息,请参阅db.collection.updateOne()db.collection.updateMany()

replaceOne

replaceOne replaces a single document in the collection that matches the filter. 替换集合中与筛选器匹配的单个文档。If multiple documents match, replaceOne will replace the first matching document only.如果多个文档匹配,replaceOne将仅替换第一个匹配的文档。

db.collection.bulkWrite([
{ replaceOne :
{
"filter" : <document>,
"replacement" : <document>,
"upsert" : <boolean>,
"collation": <document>, // Available starting in 3.4
"hint": <document|string> // Available starting in 4.2.1
}
}
] )
Field字段Notes备注
filterThe selection criteria for the replacement operation. 替换操作的选择标准。The same query selectors as in the db.collection.find() method are available.可以使用与db.collection.find()方法中相同的查询选择器
replacementThe replacement document. 替换文档。The document cannot contain update operators.文档不能包含更新运算符
upsertOptional.可选的。A boolean to indicate whether to perform an upsert. 指示是否执行追加销售的布尔值。By default, upsert is false.默认情况下,upsertfalse
collationOptional.可选的。Specifies the collation to use for the operation.指定要用于操作的排序规则
hintOptional.可选的。The index to use to support the update filter. If you specify an index that does not exist, the operation errors. 用于支持更新filter索引。如果指定的索引不存在,则操作将出错。
New in version 4.2.1. 4.2.1版新增。

For details, see to db.collection.replaceOne().有关详细信息,请参阅db.collection.replaceOne()

deleteOne and deleteMany

deleteOne deletes a single document in the collection that match the filter. 删除集合中与筛选器匹配的单个文档。If multiple documents match, deleteOne will delete the first matching document only.如果多个文档匹配,deleteOne将只删除第一个匹配的文档。

db.collection.bulkWrite([
{ deleteOne : {
"filter" : <document>,
"collation" : <document> // Available starting in 3.4
} }
] )

deleteMany deletes all documents in the collection that match the filter.删除集合中与筛选器匹配的所有文档。

db.collection.bulkWrite([
{ deleteMany: {
"filter" : <document>,
"collation" : <document> // Available starting in 3.4
} }
] )
Field字段Notes备注
filterThe selection criteria for the delete operation. 删除操作的选择条件。The same query selectors as in the db.collection.find() method are available.可以使用与db.collection.find()方法中相同的查询选择器
collationOptional.可选的。Specifies the collation to use for the operation.指定要用于操作的排序规则

For details, see db.collection.deleteOne() and db.collection.deleteMany().有关详细信息,请参阅db.collection.deleteOne()db.collection.deleteMany()

_id Field字段

If the document does not specify an _id field, then mongod adds the _id field and assign a unique ObjectId() for the document before inserting or upserting it. 如果文档没有指定_id字段,那么mongod会添加_id字段并在插入或追加文档之前为文档分配一个唯一的ObjectId()Most drivers create an ObjectId and insert the _id field, but the mongod will create and populate the _id if the driver or application does not.大多数驱动程序创建一个ObjectId并插入_id字段,但如果驱动程序或应用程序没有创建并填充_idmongod将创建并填充。

If the document contains an _id field, the _id value must be unique within the collection to avoid duplicate key error.如果文档包含_id字段,则_id值在集合中必须是唯一的,以避免重复的键错误。

Update or replace operations cannot specify an _id value that differs from the original document.更新或替换操作不能指定与原始文档不同的_id值。

Execution of Operations操作的执行

The ordered parameter specifies whether bulkWrite() will execute operations in order or not. By default, operations are executed in order.ordered参数指定bulkWrite()是否按顺序执行操作。默认情况下,操作按顺序执行。

The following code represents a bulkWrite() with five operations.以下代码表示一个包含五个操作的bulkWrite()

db.collection.bulkWrite(
[
{ insertOne : <document> },
{ updateOne : <document> },
{ updateMany : <document> },
{ replaceOne : <document> },
{ deleteOne : <document> },
{ deleteMany : <document> }
]
)

In the default ordered : true state, each operation will be executed in order, from the first operation insertOne to the last operation deleteMany.在默认的orderd:true状态下,每个操作都将按顺序执行,从第一个操作insertOne到最后一个操作deleteMany

If ordered is set to false, operations may be reordered by mongod to increase performance. 如果ordered设置为falsemongod可以重新排序操作以提高性能。Applications should not depend on order of operation execution.应用程序不应依赖于操作执行的顺序。

The following code represents an unordered bulkWrite() with six operations:以下代码表示一个包含六个操作的无序bulkWrite()

db.collection.bulkWrite(
[
{ insertOne : <document> },
{ updateOne : <document> },
{ updateMany : <document> },
{ replaceOne : <document> },
{ deleteOne : <document> },
{ deleteMany : <document> }
],
{ ordered : false }
)

With ordered : false, the results of the operation may vary. 使用ordered : false时,操作的结果可能会有所不同。For example, the deleteOne or deleteMany may remove more or fewer documents depending on whether the run before or after the insertOne, updateOne, updateMany, or replaceOne operations.例如,deleteOnedeleteMany可能会删除更多或更少的文档,具体取决于在insertOneupdateOneupdateManyreplaceOne操作之前还是之后运行。

The number of operations in each group cannot exceed the value of the maxWriteBatchSize of the database. 每个组中的操作数不能超过数据库的maxWriteBatchSize值。The default value of maxWriteBatchSize is 100,000. maxWriteBatchSize的默认值为100000This value is shown in the hello.maxWriteBatchSize field.该值显示在hello.maxWriteBatchSize字段中。

This limit prevents issues with oversized error messages. 此限制可防止出现错误消息过大的问题。If a group exceeds this limit, the client driver divides the group into smaller groups with counts less than or equal to the value of the limit. 如果一个组超过此限制,客户端驱动程序会将该组划分为计数小于或等于限制值的较小组。For example, with the maxWriteBatchSize value of 100,000, if the queue consists of 200,000 operations, the driver creates 2 groups, each with 100,000 operations.例如,当maxWriteBatchSize值为100000时,如果队列由200000个操作组成,则驱动程序将创建两个组,每个组包含100000个操作。

Note

The driver only divides the group into smaller groups when using the high-level API. 当使用高级API时,驱动程序仅将组划分为较小的组。If using db.runCommand() directly (for example, when writing a driver), MongoDB throws an error when attempting to execute a write batch which exceeds the limit.如果直接使用db.runCommand()(例如,在编写驱动程序时),MongoDB在尝试执行超过限制的写批时会抛出错误。

If the error report for a single batch grows too large, MongoDB truncates all remaining error messages to the empty string. 如果单个批次的错误报告过大,MongoDB会将所有剩余的错误消息截断为空字符串。If there are at least two error messages with total size greater than 1MB, they are trucated.如果至少有两条错误消息的总大小大于1MB,则对它们进行trucated。

The sizes and grouping mechanics are internal performance details and are subject to change in future versions.尺寸和分组机制是内部性能细节,在未来版本中可能会发生变化。

Executing an ordered list of operations on a sharded collection will generally be slower than executing an unordered list since with an ordered list, each operation must wait for the previous operation to finish.在分片集合上执行有序操作列表通常比执行无序列表慢,因为对于有序列表,每个操作都必须等待上一个操作完成。

Capped Collections封顶集合

bulkWrite() write operations have restrictions when used on a capped collection.bulkWrite()写操作在封顶集合上使用时有限制。

updateOne and updateMany throw a WriteError if the update criteria increases the size of the document being modified.如果update条件增加了要修改的文档的大小,updateOneupdateMany将抛出WriteError

replaceOne throws a WriteError if the replacement document has a larger size than the original document.如果replacement文档的大小大于原始文档的大小,replaceOne将抛出WriteError

deleteOne and deleteMany throw a WriteError if used on a capped collection.如果deleteOnedeleteMany用于封顶集合,则抛出WriteError

Time Series Collections时间序列集合

bulkWrite() write operations have restrictions when used on a time series collection. 写入操作在时间序列集合上使用时有限制。Only insertOne can be used on time series collections. All other operations will return a WriteError.只有insertOne可以用于时间序列集合。所有其他操作都将返回WriteError

Error Handling错误处理

db.collection.bulkWrite() throws a BulkWriteError exception on errors (unless the operation is part of a transaction on MongoDB 4.0). 在出现错误时抛出BulkWriteError异常(除非该操作是MongoDB 4.0上事务的一部分)。See Error Handling inside Transactions.请参阅事务内部的错误处理

Excluding write concern errors, ordered operations stop after an error, while unordered operations continue to process any remaining write operations in the queue, unless when run inside a transaction. See Error Handling inside Transactions.除了写入关注错误,有序操作在错误后停止,而无序操作继续处理队列中的任何剩余写操作,除非在事务内部运行。请参阅事务内部的错误处理

Write concern errors are displayed in the writeConcernErrors field, while all other errors are displayed in the writeErrors field. 写入关注错误显示在writeConcernErrors字段中,而所有其他错误都显示在writeErrors字段。If an error is encountered, the number of successful write operations are displayed instead of the inserted _id values. 如果遇到错误,则显示成功写入操作的次数,而不是插入的_id值。Ordered operations display the single error encountered while unordered operations display each error in an array.有序操作显示遇到的单个错误,而无序操作显示数组中的每个错误。

Transactions事务

db.collection.bulkWrite() can be used inside multi-document transactions.可以在多文档事务中使用。

Important

In most cases, multi-document transaction incurs a greater performance cost over single document writes, and the availability of multi-document transactions should not be a replacement for effective schema design. 在大多数情况下,与单文档写入相比,多文档事务会产生更高的性能成本,并且多文档事务的可用性不应取代有效的模式设计。For many scenarios, the denormalized data model (embedded documents and arrays) will continue to be optimal for your data and use cases. That is, for many scenarios, modeling your data appropriately will minimize the need for multi-document transactions.对于许多场景,非规范化数据模型(嵌入文档和数组)将继续是您的数据和用例的最佳选择。也就是说,对于许多场景,对数据进行适当建模将最大限度地减少对多文档事务的需求。

For additional transactions usage considerations (such as runtime limit and oplog size limit), see also Production Considerations.有关其他事务使用注意事项(如运行时限制和操作日志大小限制),请参阅生产注意事项

Inserts and Upserts within Transactions事务中的插入和插入

For feature compatibility version (fcv) "4.4" and greater, if an insert operation or update operation with upsert: true is run in a transaction against a non-existing collection, the collection is implicitly created.对于功能兼容性版本(fcv)“4.4”及更高版本,如果在事务中针对不存在的集合运行具有upsert:true的插入操作或更新操作,则会隐式创建该集合。

Note

You cannot create new collections in cross-shard write transactions. For example, if you write to an existing collection in one shard and implicitly create a collection in a different shard, MongoDB cannot perform both operations in the same transaction.不能在跨分片写入事务中创建新集合。例如,如果您在一个分片中写入一个现有集合,并在另一个分片中隐式创建一个集合,则MongoDB无法在同一事务中执行这两个操作。

For fcv "4.2" or less, the collection must already exist for insert and upsert: true operations.对于fcv“4.2”或更低版本,insertupsert: true操作的集合必须已经存在。

Write Concerns and Transactions撰写关注事项和事务

Do not explicitly set the write concern for the operation if run in a transaction. 如果在事务中运行,请不要显式设置操作的写入关注。To use write concern with transactions, see Transactions and Write Concern.要在事务中使用写入关注,请参阅事务和写入关注

Error Handling inside Transactions事务内部错误处理

Starting in MongoDB 4.2, if a db.collection.bulkWrite() operation encounters an error inside a transaction, the method throws a BulkWriteException (same as outside a transaction).从MongoDB 4.2开始,如果db.collection.bulkWrite()操作在事务内部遇到错误,该方法会抛出BulkWriteException(与事务外部相同)。

In 4.0, if the bulkWrite operation encounters an error inside a transaction, the error thrown is not wrapped as a BulkWriteException.在4.0中,如果bulkWrite操作在事务内部遇到错误,则抛出的错误不会包装为BulkWriteException

Inside a transaction, the first error in a bulk write causes the entire bulk write to fail and aborts the transaction, even if the bulk write is unordered.在事务内部,大容量写入中的第一个错误会导致整个大容量写入失败并中止事务,即使大容量写入是无序的。

Examples实例

Ordered Bulk Write Example有序大容量写入示例

It is important that you understand bulkWrite() operation ordering and error handling. By default, bulkWrite() runs an ordered list of operations:了解bulkWrite()操作顺序和错误处理非常重要。默认情况下,bulkWrite()运行一个有序的操作列表:

  • Operations run serially.操作以串行方式运行。
  • If an operation has an error, that operation and any following operations are not run.如果某个操作出现错误,则不会运行该操作和任何后续操作。
  • Operations listed before the error operation are completed.错误操作完成之前列出的操作。

The bulkWrite() examples use the pizzas collection:bulkWrite()示例使用pizzas集合:

db.pizzas.insertMany( [
{ _id: 0, type: "pepperoni", size: "small", price: 4 },
{ _id: 1, type: "cheese", size: "medium", price: 7 },
{ _id: 2, type: "vegan", size: "large", price: 8 }
] )

The following bulkWrite() example runs these operations on the pizzas collection:下面的bulkWrite()示例对pizzas集合运行这些操作:

  • Adds two documents using insertOne.使用insertOne添加两个文档。
  • Updates a document using updateOne.使用updateOne更新文档。
  • Deletes a document using deleteOne.使用deleteOne删除文档。
  • Replaces a document using replaceOne.使用replaceOne替换文档。
try {
db.pizzas.bulkWrite( [
{ insertOne: { document: { _id: 3, type: "beef", size: "medium", price: 6 } } },
{ insertOne: { document: { _id: 4, type: "sausage", size: "large", price: 10 } } },
{ updateOne: {
filter: { type: "cheese" },
update: { $set: { price: 8 } }
} },
{ deleteOne: { filter: { type: "pepperoni"} } },
{ replaceOne: {
filter: { type: "vegan" },
replacement: { type: "tofu", size: "small", price: 4 }
} }
] )
} catch( error ) {
print( error )
}

Example output, which includes a summary of the completed operations:示例输出,其中包括已完成操作的摘要:

{
acknowledged: true,
insertedCount: 2,
insertedIds: { '0': 3, '1': 4 },
matchedCount: 2,
modifiedCount: 2,
deletedCount: 1,
upsertedCount: 0,
upsertedIds: {}
}

If the collection already contained a document with an _id of 4 before running the previous bulkWrite() example, the following duplicate key exception is returned for the second insertOne operation:如果在运行上一个bulkWrite()示例之前,集合已包含一个_id4的文档,则第二个insertOne操作将返回以下重复键异常:

writeErrors: [
WriteError {
err: {
index: 1,
code: 11000,
errmsg: 'E11000 duplicate key error collection: test.pizzas index: _id_ dup key: { _id: 4 }',
op: { _id: 4, type: 'sausage', size: 'large', price: 10 }
}
}
],
result: BulkWriteResult {
result: {
ok: 1,
writeErrors: [
WriteError {
err: {
index: 1,
code: 11000,
errmsg: 'E11000 duplicate key error collection: test.pizzas index: _id_ dup key: { _id: 4 }',
op: { _id: 4, type: 'sausage', size: 'large', price: 10 }
}
}
],
writeConcernErrors: [],
insertedIds: [ { index: 0, _id: 3 }, { index: 1, _id: 4 } ],
nInserted: 1,
nUpserted: 0,
nMatched: 0,
nModified: 0,
nRemoved: 0,
upserted: []
}
}

Because the bulkWrite() example is ordered, only the first insertOne operation is completed.因为bulkWrite()示例是有序的,所以只完成了第一个insertOne操作。

To complete all operations that do not have errors, run bulkWrite() with ordered set to false. For an example, see the following section.若要完成所有没有错误的操作,请在ordered设置为false的情况下运行bulkWrite()。有关示例,请参阅以下部分。

Unordered Bulk Write Example无序大容量写入示例

To specify an unordered bulkWrite(), set ordered to false.若要指定无序的bulkWrite(),请将ordered设置为false

In an unordered bulkWrite() list of operations:在无序的bulkWrite()操作列表中:

  • Operations can run in parallel (not guaranteed). 操作可以并行运行(不保证)。For details. See Ordered vs Unordered Operations.请参阅有序操作与无序操作以了解详细信息。
  • Operations with errors are not completed.有错误的操作未完成。
  • All operations without errors are completed.所有没有错误的操作都已完成。

Continuing the pizzas collection example, drop and recreate the collection:继续pizzas集合示例,放下并重新创建该系列:

db.pizzas.insertMany( [
{ _id: 0, type: "pepperoni", size: "small", price: 4 },
{ _id: 1, type: "cheese", size: "medium", price: 7 },
{ _id: 2, type: "vegan", size: "large", price: 8 }
] )

In the following example:在以下示例中:

  • bulkWrite() runs unordered operations on the pizzas collection.pizzas集合执行无序操作。
  • The second insertOne operation has the same _id as the first insertOne, which causes a duplicate key error.第二个insertOne操作具有与第一个insertOne相同的_id,这会导致重复键错误。
try {
db.pizzas.bulkWrite( [
{ insertOne: { document: { _id: 3, type: "beef", size: "medium", price: 6 } } },
{ insertOne: { document: { _id: 3, type: "sausage", size: "large", price: 10 } } },
{ updateOne: {
filter: { type: "cheese" },
update: { $set: { price: 8 } }
} },
{ deleteOne: { filter: { type: "pepperoni"} } },
{ replaceOne: {
filter: { type: "vegan" },
replacement: { type: "tofu", size: "small", price: 4 }
} }
],
{ ordered: false } )
} catch( error ) {
print( error )
}

Example output, which includes the duplicate key error and a summary of the completed operations:输出示例,其中包括重复键错误和已完成操作的摘要:

writeErrors: [
WriteError {
err: {
index: 1,
code: 11000,
errmsg: 'E11000 duplicate key error collection: test.pizzas index: _id_ dup key: { _id: 3 }',
op: { _id: 3, type: 'sausage', size: 'large', price: 10 }
}
}
],
result: BulkWriteResult {
result: {
ok: 1,
writeErrors: [
WriteError {
err: {
index: 1,
code: 11000,
errmsg: 'E11000 duplicate key error collection: test.pizzas index: _id_ dup key: { _id: 3 }',
op: { _id: 3, type: 'sausage', size: 'large', price: 10 }
}
}
],
writeConcernErrors: [],
insertedIds: [ { index: 0, _id: 3 }, { index: 1, _id: 3 } ],
nInserted: 1,
nUpserted: 0,
nMatched: 2,
nModified: 2,
nRemoved: 1,
upserted: []
}
}

The second insertOne operation fails because of the duplicate key error. 由于重复键错误,第二个insertOne操作失败。In an unordered bulkWrite(), any operation without an error is completed.在无序的bulkWrite()中,任何没有错误的操作都将完成。

Bulk Write with Write Concern Example带写入关注的大容量写入示例

Continuing the pizzas collection example, drop and recreate the collection:继续pizzas系列示例,放下并重新创建该系列:

db.pizzas.insertMany( [
{ _id: 0, type: "pepperoni", size: "small", price: 4 },
{ _id: 1, type: "cheese", size: "medium", price: 7 },
{ _id: 2, type: "vegan", size: "large", price: 8 }
] )

The following bulkWrite() example runs operations on the pizzas collection and sets a "majority" write concern with a 100 millisecond timeout:下面的bulkWrite()示例对pizzas集合运行操作,并设置一个"majority"写入关注,超时时间为100毫秒:

try {
db.pizzas.bulkWrite( [
{ updateMany: {
filter: { size: "medium" },
update: { $inc: { price: 0.1 } }
} },
{ updateMany: {
filter: { size: "small" },
update: { $inc: { price: -0.25 } }
} },
{ deleteMany: { filter: { size: "large" } } },
{ insertOne: {
document: { _id: 4, type: "sausage", size: "small", price: 12 }
} } ],
{ writeConcern: { w: "majority", wtimeout: 100 } }
)
} catch( error ) {
print( error )
}

If the time for the majority of replica set members to acknowledge the operations exceeds wtimeout, the example returns a write concern error and a summary of completed operations:如果大多数副本集成员确认操作的时间超过wtimeout,则此示例将返回一个写入关注错误和已完成操作的摘要:

result: BulkWriteResult {
result: {
ok: 1,
writeErrors: [],
writeConcernErrors: [
WriteConcernError {
err: {
code: 64,
codeName: 'WriteConcernFailed',
errmsg: 'waiting for replication timed out',
errInfo: { wtimeout: true, writeConcern: [Object] }
}
}
],
insertedIds: [ { index: 3, _id: 4 } ],
nInserted: 0,
nUpserted: 0,
nMatched: 2,
nModified: 2,
nRemoved: 0,
upserted: [],
opTime: { ts: Timestamp({ t: 1660329086, i: 2 }), t: Long("1") }
}
}