查询嵌套的mongdb文档的属性

时间:2019-04-02 18:44:38

标签: node.js mongodb mongoose mongodb-query mongoose-schema

我正在尝试查询嵌套对象的属性,但到目前为止还没有运气。假设我的文档看起来像:

{
"_id":"PE",
"code": {
    "5.1": "4.1",
    "5.2":"4.2",
    "6.1":"5.1",
    "6.2":"5.2",
    "7.1":"6.1",
    "7.2":"6.2",
    "7.3":"6.3",
    "7.4":"6.4",
    "8.1":"7.1",
    "8.2":"7.2",
    "8.3":"7.3",
    "9":"8",
    "10.1":"9.1"}
}

当我查询db.collection('xyz').find({id:PEI})时,我可以访问此对象,现在我要从这里进入代码,并说通过使用'code中的键4.1获得值5.1 '对象。我将如何实现这一目标?预先感谢!

0 个答案:

没有答案