【发布时间】:2018-10-08 05:40:01
【问题描述】:
我在这里要做的是,我只想要那些在提供的纬度和经度内的子文档,但如果我的文档中只有一个子文档匹配而其他子文档不匹配,它应该只返回包含该特定文档的文档。但它也将所有子文档都归还给我,你们可以帮助我。 我的文档是这样的
{
"_id": "5ae04fd45f104a5980cf7e0e",
"name": "Rehan",
"email": "rehan@gmail.com",
"status": true,
"created_at": "2018-04-25T09:52:20.266Z",
"parking_space": [
{
"_id": "5ae05dce5f104a5980cf7e0f",
"parking_name": "my space 1",
"restriction": "no",
"hourly_rate": "3",
"location": {
"type": "Point",
"coordinates": [
86.84470799999997,
42.7052881
]
},
},
{
"_id": "5ae06d4d5f104a5980cf7e52",
"parking_name": "my space 2",
"restriction": "no",
"hourly_rate": "6",
"location": {
"type": "Point",
"coordinates": [
76.7786787,
30.7352527
]
},
}
],
},
{
"_id": "5ae2f8148d51db4937b9df02",
"name": "nellima",
"email": "neel@gmail.com",
"status": true,
"created_at": "2018-04-27T10:14:44.598Z",
"parking_space": [
{
"_id": "5ae2f89d8d51db4937b9df04",
"parking_name": "my space 3",
"restriction": "no",
"hourly_rate": "60",
"location": {
"type": "Point",
"coordinates": [
76.7786787,
30.7352527
]
},
}
],
},
}
我正在应用这个查询。
User.find({
"parking_space.location": {
"$geoWithin": {
"$centerSphere": [
[76.7786787, 30.7352527], 7 / 3963.2
]
}
},
}, function(err, park_places) {
if (err) {
return res.send({
data: err,
status: false
});
} else {
return res.send({
data: park_places,
status: true,
msg: "Parking data according to location"
});
}
});
我正在尝试获取这样的数据。
{
"_id": "5ae04fd45f104a5980cf7e0e",
"name": "Rehan",
"email": "rehan@gmail.com",
"status": true,
"created_at": "2018-04-25T09:52:20.266Z",
"parking_space": [
{
"_id": "5ae06d4d5f104a5980cf7e52",
"parking_name": "my space 2",
"restriction": "no",
"hourly_rate": "6",
"location": {
"type": "Point",
"coordinates": [
76.7786787,
30.7352527
]
},
}
],
},
{
"_id": "5ae2f8148d51db4937b9df02",
"name": "nellima",
"email": "neel@gmail.com",
"status": true,
"created_at": "2018-04-27T10:14:44.598Z",
"parking_space": [
{
"_id": "5ae2f89d8d51db4937b9df04",
"parking_name": "my space 3",
"restriction": "no",
"hourly_rate": "60",
"location": {
"type": "Point",
"coordinates": [
76.7786787,
30.7352527
]
},
}
],
},
}
有没有可能得到这样的数据。
【问题讨论】:
-
谁能帮帮我
-
您认为提供的答案中是否有某些内容无法解决您的问题?如果是这样,那么请对答案发表评论,以澄清究竟需要解决哪些尚未解决的问题。如果它确实回答了您提出的问题,请注意Accept your Answers您提出的问题
标签: node.js mongodb mongoose mongodb-query geospatial