我正试图在我的流星项目中获得最近的帖子。它返回我的四个帖子,但没有按原点距离排序。我添加了这两个索引:
db.postings.ensureIndex({ loc : "2d" })
db.postings.ensureIndex({ loc : "2dsphere" })
并运行以下查询:
Postings.find loc:
$near:
$geometry:
type: "Point"
coordinates: [ 39.107225, -84.501956 ]
但它按此顺序返回:
_id:xs.. 39.239881, -84.359919 15.2 miles (according to google maps)
_id:aK.. 39.239881, -84.359919 15.2 miles
_id:8z.. 39.107225, -84.50195600000001 0 miles
_id:An.. 39.405906, -84.52211699999999 30.5 miles
以下是一个示例文档:
{
"_id": "xsTpnpw7eCAgFS565",
"loc": [39.239881, -84.359919]
}
答案 0 :(得分:0)
试试这个:
Postings.find loc:
$near: [ 39.107225, -84.501956 ]