如何使用Node.js在MongoDB中获取文档的一部分?

狮子之心
"Geography": {
  "Tourism": {
    "B001": {
      "code": "B001",
      "max": " 140",
      "min": " 97",
      "minWithQuota": " 91"
    }
  }
},
"MathAndPhysic": {
  "IT": {
    "B183": {
      "code": "B183",
      "max": "140",
      "min": " 50",
      "minWithQuota": "none",
      "quotes": []
    }
  }
}

我有一些收藏,我只想获得“ B001”对象。我试图通过它

db.subjects.findOne (
{"Geography.Tourism.B001": {$exists: true}},
{_id: 1," Geography.Tourism.B001": 1})

但结果是整个文档。我怎么得到这个结果?

"B001": {
      "code": "B001",
      "max": " 140",
      "min": " 97",
      "minWithQuota": " 91"
    }

PS有趣的是,如果您尝试在MongoShell中使用相同的命令,则将获得所需的结果

土生的

尝试使用参考来投影字段$

db.subjects.findOne(
  { "Geography.Tourism.B001": { $exists: true } },
  { "B001": "$Geography.Tourism.B001" }
);

操场

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章