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 · 3975 次点击
    这是一个创建于 3486 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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   ·   实用小工具   ·   991 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 20:18 · PVG 04:18 · LAX 12:18 · JFK 15:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.