2014-11-06 86 views
1

我射击下面的查询MongoDB中MongoDB的附近找到maxdistance

db.acollection.find({ 
    "field.location": { 
     "$near": [19.0723058, 73.00067739999997] 
    }, 
    $maxDistance : 100000 
}).count() 

,并收到以下错误 -

uncaught exception: count failed: { 
    "shards" : { 

    }, 
    "cause" : { 
     "errmsg" : "exception: unknown top level operator: $maxDistance", 
     "code" : 2, 
     "ok" : 0 
    }, 
    "code" : 2, 
    "ok" : 0, 
    "errmsg" : "failed on : Shard ShardA" 
} 

回答

3

你没有错。该$maxDistance参数是在$near运营商的“孩子”:

db.acollection.find({ 
    "field.location": { 
     "$near": [19.0723058, 73.00067739999997], 
     "$maxDistance": 100000 
    } 
}).count() 

具有相同的表达中。

当你正在创建一个新的应用程序时,还要看看GeoJSON。这是您未来应该储存的方式。