我有以下收藏:
消息收集
[{
_id: ObjectId("5ca432dcac7e52100bb7589b"),
message: "Hello"
},
{
_id: ObjectId("5ca432dcac7e52100bb7579b"),
message: "Hi There"
}]
促进消息收集
[{
_id: ObjectId(),
msgId: ObjectId("5ca432dcac7e52100bb7589b"),
"filter": {
"location": {
"type": "miles",
"miles": 20,
"cities": [{
"name": "Rajkot",
"_id": ObjectId(),
"location": {
"type": "point",
"coordinates": [70.8021599,
22.3038945]
}
},
{
"name": "Ahmedabad",
"_id": ObjectId(),
"location": {
"type": "point",
"coordinates": [72.5713621,
23.022505]
}
}]
}
}
}]
用户集合
{
_id: ObjectId(),
name: "user 1",
"location": {
"coordinates": [72.5351,
23.1105],
"type": "Point"
}
}
我想为所有半径已定义的城市找到属于升级消息边界的消息。
例如属于“ Rajkot”城市边界(市中心20英里)的用户
我一直在寻找$geoWithin
,但它是针对用户半径的,我希望它可以与城市半径一起使用。
{
$match: {
"promotedMessage.filter.location.cities.location.coordinates": {
$geoWithin: {
$centerSphere: [[72.5351, 23.1105], 5000 / 3963.2]
}
}
}
}