Mongodb 我如何才能获得收藏“;社区”;第一个数据的
如何获取第一个数据的集合Mongodb 我如何才能获得收藏“;社区”;第一个数据的,mongodb,Mongodb,如何获取第一个数据的集合“社区”。我使用“db.test.find({“community.communityId”:“community001”})”返回“community”如果要限制数组的内容,请使用: { "_id": ObjectId('58d0789eb9031ac824000001'), "propertyId": "property001", "title": "test1", "imageUrl": "", "contact": "tom
“社区”
。我使用“db.test.find({“community.communityId”:“community001”})”
返回“community”
如果要限制数组的内容,请使用:
{
"_id": ObjectId('58d0789eb9031ac824000001'),
"propertyId": "property001",
"title": "test1",
"imageUrl": "",
"contact": "tom",
"contactphone": "045182321127",
"community": [
{
"_id": "123456789",
"communityId": "community001",
"title": "communitytest",
"imageUrl": "",
"contact": "tom",
"contactphone": "045182321127"
},
{
"communityId": "community002",
"title": "communitytest",
"imageUrl": "",
"contact": "jack",
"contactphone": "045182321127"
},
{
},
{
"communityId": "community003",
"title": "communitytest3",
"imageUrl": "",
"contact": "sfva",
"contactphone": "045182321127"
}
]
}
如果要按社区数组中只有必填项的文档筛选文档,则可以保留筛选器。不清楚第一个数据是什么意思。请添加您现在拥有的预期结果和查询Hi Sergey-我认为您需要强调的关键是您正在添加一个;OP似乎还不熟悉预测。
db.test.find({}, {community: { $elemMatch: {communityId: "community001"}}})