【发布时间】:2021-01-23 16:41:30
【问题描述】:
我有记录:
{
"name" : "user",
"number":"09xxxxxxx21",
"pc" : [{
"pcId" : "1",
"pcName" : "Lenovo",
"pcOwner" : "user1",
"using" : true
}, {
"pcId" : "2",
"pcName" : "Lenovo",
"pcOwner" : "user1",
"using": false
}, {
"pcId" : "3",
"pcName" : "Dell",
"pcOwner" : "user1",
"using": true
}, {
"pcId" : "4",
"pcName" : "Dell",
"pcOwner" : "user1",
"using": true
}
]}
}
使用查询 .find({'pcID':'4','pc.pcName':'Dell'}) 我得到了完整的记录,但我想记录我只有 pcName:'Dell' 的地方。
类似的东西:
{
"name" : "user",
"number":"09xxxxxxx21",
"pc" : [
{
"pcId" : "3",
"pcName" : "Dell",
"pcOwner" : "user1",
"using": true
},
{
"pcId" : "4",
"pcName" : "Dell",
"pcOwner" : "user1",
"using": true
}
]}
}
或者只有那两个对象。
【问题讨论】:
-
任何查询都可以得到预期的输出?
标签: mongodb mongoose mongodb-query