我想在總管道使用$ geoWithin查詢,但我得到一個一個
MongoError: exception: bad query: BadValue bad geo query: { $geoWithin: { $box: [ [ "13.618240356445312", "51.01343066212905" ], [ "13.865432739257812", "51.09662294502995" ] ] } }
我的查詢:
{
$match: {
'gps.coordinates.matched': {
$geoWithin: {
$box: [
[ swlng, swlat ],
[ nelng , nelat ]
]
}
}
}
},
{ $project : {shortGeohash: {$substr: ["$gps.geohash.original", 0, 11]}}},
{ $group: {_id: "$shortGeohash", count: {$sum:1}, originalDoc:{$push: "$$ROOT"}}}
查詢只有$geoWithin
以及$project...,$group
自己運行良好,但組合發生錯誤。
嗯。你真的用'[]'把你的管道封裝成適當的數組標識符嗎?更何況'$$ ROOT'沒有達到我認爲你期望的效果。它只是「當前」階段的「整個」文檔,而不是「$ project」修改之前的「原始」文檔。 –
我以前沒有這樣做過,但是將它包裝成一個數組會導致相同的錯誤,在那裏沒有任何更改。的確,'$$ ROOT'沒有像我打算做的那樣工作,但它至少給了我'ObjectId',這對我來說工作得很好。 – florianschmidt1994
你會更好地編輯你的問題,並提供人們可以測試和重現的例子。現在我只是說,「適合我」。但是,當你做錯了事情的時候,確實要把這個'$$ ROOT'的評論放在心上。 –