$near cost too much time

2015-05-07 09:37:46 +08:00
 nevernet
code as below:

```
db.postspreads.find({"location":{"$nearSphere":{"$geometry":{"type":"Point","coordinates":[113.558206,22.159933]},"$maxDistance":1}},"countavailablespreads":{"$gt":0},"timestamp":{"$gt":1430409600},"accountid":{"$ne":254695}}, {'_id':1}).limit(100).explain()
{
"cursor" : "S2NearCursor",
"isMultiKey" : false,
"n" : 100,
"nscannedObjects" : 25626,
"nscanned" : 25626,
"nscannedObjectsAllPlans" : 25626,
"nscannedAllPlans" : 25626,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 239,
"nChunkSkips" : 0,
"millis" : 2244,
"indexBounds" : {

},
"server" : "DB-SH-01:27017",
"filterSet" : false
}
```
i dont know why it will cost more than 2 seconds.


document structure:
```
{
"_id":ObjectId("55483f3e297b5043c7a2b099"),
"postid":NumberLong(142462),
"spreadid":"55474131297b5043c6451ac0",
"accountid":NumberLong(257074),
"location":{
"type":"Point",
"coordinates":[
113.558206,
22.159933
]
},
"city":"null",
"country":"null",
"type":NumberLong(1),
"countspreads":NumberLong(51),
"countavailablespreads":NumberLong(51),
"timestamp":NumberLong(1430798142),
"createdtime":ISODate("2015-05-05T03:55:42Z")
}
```
please pay attention on location node.

please advise how to optimize it.

thank you in advantage.
3975 次点击
所在节点    MongoDB
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/189101

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX