5. Consider the following set of commands executed in the mongo shell: > db.products.drop() > db.products.insert([ { "name": "Spiral Notebook", "price": 2.00, qty: 20, "_id": 1}, { "name": "A4 Notebook", "price": 4.00, qty: 100, "_id": 2}, { "name": "Pocket Notebook", "price": 1.50, qty: 10, "_id": 3}, { "name": "Lined Notebook", "price": 1.60, qty: 10, "_id": 1}, ]) What are/is the outcome of these insert() operation be in the mongo shell? Check all that apply:
题目选项
- A.BulkWriteResult is the type of result shown in the output.
- B.nInserted indicates that 3 documents were inserted.
- C.nInserted indicates that 4 documents were inserted.
- D.InsertResult is the type of result shown in the output.
答案置信度:高
正确答案:A、B
解析语言:中文
在 mongo shell 里用数组调用 insert() 会走批量写入路径,输出的结果是 BulkWriteResult(A)。第 4 个文档 _id 为 1,与第 1 个文档重复,触发 E11000 唯一键冲突;默认 ordered:true,遇到错误后不再继续后续插入,所以 nInserted 是 3 而不是 4(B)。D 提到的 InsertResult 类型并不存在。