2014-11-06 71 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。這是您未來應該儲存的方式。