MongoDB DBA · Question 488 · Multiple choice

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:

Answer options

  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.

Answer confidence: High

Correct answer: A, B

Explanation language: Chinese

在 mongo shell 里用数组调用 insert() 会走批量写入路径,输出的结果是 BulkWriteResult(A)。第 4 个文档 _id 为 1,与第 1 个文档重复,触发 E11000 唯一键冲突;默认 ordered:true,遇到错误后不再继续后续插入,所以 nInserted 是 3 而不是 4(B)。D 提到的 InsertResult 类型并不存在。

Papers containing this question

This question appears in 1 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗