【问题标题】:MongoDB Projection of a subdocument子文档的 MongoDB 投影
【发布时间】:2013-02-25 23:54:18
【问题描述】:

如何使用 MongoDB 查询预测作者的名字

{
 name: "Wings Of Fire",
 author:
 {
  first: "Abdul",
  last: "Kalam"
 }
}

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    您可以在字段选择器中使用dot notation 来投影子文档字段。在外壳中:

    db.test.find({}, {'author.first': 1})
    

    【讨论】:

    • $project 也可以使用。 db.test.aggregate([{$project:{"_id":1,"author.first":1}}])
    猜你喜欢
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    相关资源
    最近更新 更多