0
當我進行查詢以找到最近的子文檔與查詢我使此:mongodb地理空間子查詢在數組中,如何返回最接近查詢的數組元素?
查詢:
db.areas.findOne(
{ 'coordinates.geoindex' :
{ $near : [ 2.364022, 48.896606 ] }
}
)
它返回一個包含具有與查詢最近的元件陣列的文檔。 但我想找到最近的子元素。
例如,對於那個查詢,我應該先找到第二個數組項「Aubervilliers」。
你認爲這是可能的嗎?
文檔樣式:
{
"_id" : ObjectId("5199335f6db079ede30000"),
"commercial_name" : "Paris area",
"coordinates" : [
{
"long_name" : "Arcueil",
"short_name" : "Arcueil",
"geoindex" : [
2.334955,
48.80486
]
},
{
"long_name" : "Aubervilliers",
"short_name" : "Aubervilliers",
"geoindex" : [
2.384049,
48.912259
]
},
{
"long_name" : "Bagnolet",
"short_name" : "Bagnolet",
"geoindex" : [
2.4234589,
48.870364
]
},
{
"long_name" : "Boulogne-Billancourt",
"short_name" : "Boulogne-Billancourt",
"geoindex" : [
2.237803,
48.84325
]
},
{
"long_name" : "Charenton",
"short_name" : "Charenton-le-Pont",
"geoindex" : [
2.4158559,
48.819918
]
}
...
謝謝!我將用引用創建單獨的集合。 – LeGilles