How would the following query change if we set { upsert: true } as the third parameter? db.sample.updateMany( { a: 4 }, { $set: { b: 2, d: -4 } } ) Check all that apply:
题目选项
- A.The upsert will both insert and update a document.
- B.The upsert will insert a document if no documents exist where "a" is equal to 4
- C.An upsert will remove a document, if found, before inserting a new document.
答案置信度:高
正确答案:B
解析语言:中文
updateMany 加 upsert: true 的语义是:没有文档匹配 { a: 4 } 时插入一条新文档(插入内容由查询条件与 $set 共同构成),有匹配时只做更新,绝不会“既更新又插入”(A 错)。upsert 不会删除任何文档,因此 C 也错。