MongoDB DBA · 题目 488 · 多选

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:

题目选项

  1. A.
    BulkWriteResult is the type of result shown in the output.
  2. B.
    nInserted indicates that 3 documents were inserted.
  3. C.
    nInserted indicates that 4 documents were inserted.
  4. 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 类型并不存在。

所在套题

此题在题库中有 1 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗