V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
nevernet
V2EX  ›  MongoDB

$near cost too much time

  •  
  •   nevernet · 2015-05-07 09:37:46 +08:00 · 3787 次点击
    这是一个创建于 3248 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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.
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1240 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:03 · PVG 02:03 · LAX 11:03 · JFK 14:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.