简体   繁体   English

在 MongoDB 中使用嵌套属性查找文档

[英]Find a document using nested property in MongoDB

Having a document of this form拥有此表格的文件

{ "id" : 1,
  "data": "some_data"
}

the method I'm using to find it is this one我用来找到它的方法就是这个

myModel.findOne({ id: req.params.id})

this works fine, but now the model has changed and it looks like this这工作正常,但现在 model 已经改变,看起来像这样

{  "item": {
       "id": 1
    },
   "data": "some_data",
}

tying like this doesn't seem to work: 像这样捆绑似乎不起作用:

myModel.findOne({ item: { id: req.params.id } })

any ideas?有任何想法吗?

You can try the following:您可以尝试以下方法:

myModel.findOne({ 'item.id': req.params.id})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM