MongoDB DBA · 题目 487 · 单选

4. Consider the following document: { "_id": 12, "a": [] } Which of the following commands will append the value 5 to the array in the a field? Choose the best answer:

题目选项

  1. A.
    db.sample.updateOne({ "_id": 12 }, { $pop: { "a": 5 } })
  2. B.
    db.sample.updateOne({ $push: { "a": 5 } }, { "_id": 12 })
  3. C.
    db.sample.updateOne({ "_id": 12 }, { $push: { "a": 5 } })
  4. D.
    db.sample.updateOne({ "_id": 12, "a": { $exists: true } }, { $push: { "a": 5 } })

答案置信度:低

正确答案:D

解析语言:中文

过滤条件 {_id:12, a:{$exists:true}} 能匹配 a 为空数组的文档(字段存在即匹配),$push 会把 5 追加到该数组,因此 A 可以达到目的。但本题选项存在歧义:D 的 {_id:12} 同样能匹配并完成追加,两种写法结果完全一致,题目却要求单选;源卷把答案记为 A,故按 A 判定并降低置信度。

所在套题

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

作者 · 作品 · 开源

作者与 MongoDB 作品

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

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

联系作者 ↗mlhp123@outlook.com

支持作者

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

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