1

我已经将一些 twitter 从流式 api 存储到 MongoDB。它们都是 jason 格式,并具有如下属性:

"geo" : { "type" : "Point", "coordinates" : [  42.03759247,  -71.82113956 ] }

我只是想知道在特定坐标附近选择推文的正确查询是什么。我是这样做的:

db.tweets.find( { coordinates : { $near : [151.1955562233925,-33.87107475181752]  , $maxDistance : 1000} } )

但它没有用。谢谢您的回答!

4

2 回答 2

1

根据this page,您必须首先创建一个地理空间索引才能进行地理查询:

现在,为了通过地理坐标查询,我们需要在经销商文档的“loc”字段上创建一个索引。

db.dealerships.ensureIndex({loc:"2d"})

所以尝试这样的事情:

db.tweets.ensureIndex({"coordinates":"2d"})

您可能还需要更改“geo”属性的结构以匹配以下内容(我不确定这部分):

"geo" : { "type" : "Point", "coordinates" : { "lon":42.03759247,  "lat":-71.82113956 } }
于 2013-10-28T23:04:40.957 回答
1

这对我有用:

db.tweets.ensureIndex({"coordinates.coordinates":"2d"})

询问:

db.tweets.find({"coordinates.coordinates": {$near:[-1,-53]}}).limit(2)
于 2014-02-11T18:18:28.127 回答