MongoDB DEV · 题目 185 · 单选

Consider a collection called products. Which of the following documents from the products collection will be returned by this query? db.products.find({ "brand": "appl" }, { "name": 1, "reviews.stars": 1 }) Choose the best answer:

题目选项

  1. A.
    { "name": "flip", "reviews": [ { "stars": 10 } ] }
  2. B.
    { "_id": ObjectId("5ab056adf1bdee44989b912e"), "name": "flip", "brand": "appl", "reviews": [ { "stars": 10 } ] }
  3. C.
    { "_id": ObjectId("5ab056adf1bdee44989b912e"), "name": "flip", "reviews": [ { "stars": 10 } ] }
  4. D.
    { "brand": "appl", "name": 1, "reviews": { "stars": 1 } }
  5. E.
    { "_id": ObjectId("5ab056adf1bdee44989b912e"), "brand": "appl" }

答案置信度:高

正确答案:C

解析语言:中文

投影 { name: 1, reviews.stars: 1 } 只输出 name,以及 reviews 数组中每个子文档的 stars 字段;除非显式写 _id: 0,_id 默认保留,所以结果形如 { _id, name, reviews: [ { stars: 10 } ] },即 C。A 少了 _id(默认会带)、B 多带了被投影排除的 brand、D/E 的形态根本不是查询结果的写法。

所在套题

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

作者 · 作品 · 开源

作者与 MongoDB 作品

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

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

联系作者 ↗mlhp123@outlook.com

支持作者

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

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