mongodb在数组中查找对象
有人可以帮助我找到一个解决方案以在MongoDB文档中找到一个数组对象,我尝试了几种方法,但仍然无法获得我需要的对象,我正在尝试根据用户数据EG查找来查询使用用户电子邮件和名称,这是我想在文档中找到数组的文档。
{
"_id": "lfe78vlwncr",
"images": [],
"location": [28.1339088, -26.2098077],
"_p_category": "Category$ZjfUGGzbNb",
"image": "5d4663900459815806965d8af5392190_image.jpg",
"imageName": "5d4663900459815806965d8af5392190_image.jpg",
"imageThumb": "5d4663900459815806965d8af5392190_image.jpg",
"isHead": "1",
"storeNumber": null,
"twitter": null,
"superUser": null,
"youtube": null,
"user": {
"email": "[email protected]",
"name": "john"
},
"_created_at": "2022-03-15T08:17:46.769Z",
"status": "Approved",
"_wperm": ["*"],
"_rperm": ["*"],
"_acl": {
"w": "true",
"r": "true"
},
"bIsSales": "true",
"_updated_at": "2022-03-17T05:06:38.425Z",
"bShow": true,
"imageFour": "49217bd1ccf227f010562be0b9e0b889_image.jpg",
"imageThree": "998866aa6707b520f8a6d214351b6256_image.jpg",
"imageTwo": "a394516d65948af07033ac8812d225b8_image.jpg",
}
这是我到目前为止尝试的方法,但仍无法使用。
db.collection("Place")
.find({
user: {
email: req.body.userEmail,
name: req.body.userName
}
})
.toArray(function(err, result) {
if (err) throw err;
res.json(result);
});
Can someone help me with a solution to find an array object inside the MongoDB document, I've tried a couple of methods but am still not able to get the object that I need I'm trying to query based on the user data e.g finding using user email and name, here is the document that I want to find array in the document.
{
"_id": "lfe78vlwncr",
"images": [],
"location": [28.1339088, -26.2098077],
"_p_category": "Category$ZjfUGGzbNb",
"image": "5d4663900459815806965d8af5392190_image.jpg",
"imageName": "5d4663900459815806965d8af5392190_image.jpg",
"imageThumb": "5d4663900459815806965d8af5392190_image.jpg",
"isHead": "1",
"storeNumber": null,
"twitter": null,
"superUser": null,
"youtube": null,
"user": {
"email": "[email protected]",
"name": "john"
},
"_created_at": "2022-03-15T08:17:46.769Z",
"status": "Approved",
"_wperm": ["*"],
"_rperm": ["*"],
"_acl": {
"w": "true",
"r": "true"
},
"bIsSales": "true",
"_updated_at": "2022-03-17T05:06:38.425Z",
"bShow": true,
"imageFour": "49217bd1ccf227f010562be0b9e0b889_image.jpg",
"imageThree": "998866aa6707b520f8a6d214351b6256_image.jpg",
"imageTwo": "a394516d65948af07033ac8812d225b8_image.jpg",
}
here is what I tried so far yet still not working.
db.collection("Place")
.find({
user: {
email: req.body.userEmail,
name: req.body.userName
}
})
.toArray(function(err, result) {
if (err) throw err;
res.json(result);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样的尝试:
Playground
Try it like this:
Playground