我有2个mongodb集合。即城市,国家。
以下是示例城市文档:
城市:
{
"_id" : "4d941c4a-0902-4fb5-942f-54ad27e04f64",
"type" : "City",
"centroid" : {
"coordinates" : [
122.1352778114,
7.706111098
],
"type" : "Point"
},
"country_code" : "PH",
"display_name_components" : [
"Siocon"
],
"geometry" : {
"coordinates" : [
[
[
122.126210749328,
7.6970664546708
],
[
122.126210749328,
7.71515574136492
],
[
122.144344873494,
7.71515574136492
],
[
122.144344873494,
7.6970664546708
],
[
122.126210749328,
7.6970664546708
]
]
],
"type" : "Polygon"
}
}
以下是样本国家文档。 国家/地区:
{
"_id": "2064fb31-bf7f-4d55-b268-b9bd28b55c9f",
"type": "Country",
"centroid": {
"coordinates": [
-53.056356166,
-10.7556598919
],
"type": "Point"
},
"country_code": "BR",
"display_name_components": [
"Brazil"
],
"geometry": {
"coordinates": [
[
[
[
-28.8566613557,
-20.4695035781
],
[
-28.8552613676,
-20.4674338297
],
[
-28.8471194672,
-20.474721977
],
[
-28.8468522896,
-20.4971849508
],
[
-28.8474634864,
-20.4981487997
],
[
-28.8506478079,
-20.4969826958
],
[
-28.8566613557,
-20.4695035781
]
]
]
],
"type": "MultiPolygon"
}
}
目标:
我希望对附近的地理位置进行查询,以查找所有质心位于特定国家/地区几何图形内的城市,而无需进行任何其他查询来首先获取该国家/地区的几何图形。
db.City.find( { centroid :
{ $geoWithin :
{ $geometry : {
--- some reference to a country's geometry field
}
}
}
})
有可能吗?我该怎么办?