12. When an index is created on the "name" field in the "friends" collection, which operation(s) will become more efficient as a result? Check all that apply:
题目选项
- A.db.friends.insert({"name": "John", "age": 12})
- B.db.friends.updateOne({"name": "Karen"}, {"$set": {"age":15}})
- C.db.friends.find({"name": "Emily"})
答案置信度:高
正确答案:B、C
解析语言:中文
在 name 上建索引后,任何带 name 条件的操作都能先用索引定位目标文档:C 的 find({"name":"Emily"}) 直接走索引;B 的 updateOne 也先用 {name:"Karen"} 定位再修改,因此都比全集合扫描更高效。A 是插入操作,每插一条都要额外维护 name 索引,插入反而变慢(而且它没有 name 条件可用索引查找),所以不选。