2017-01-20 362 views
9

我需要在我的網站中整合英里/距離搜索,並且我正在使用mongodb地理空間索引,但是我收到了一些無法解決的問題。下面是我的架構和指令featureCompatibilityVersion必須爲3.4才能使用整理

=> db.properties.findOne({},{address:1}) 
{ 
    "_id" : ObjectId("585b909c870d907845b695fd"), 
    "address" : { 
     "postcode" : "W1D 1NN", 
     "address1" : "Essence", 
     "address2" : "United Kingdom House", 
     "county" : "London", 
     "town" : "LONDON", 
     "latitude" : "51.5160229933117", 
     "longitude" : "-0.139088472429092", 
     "house_number" : "114", 
     "location" : { 
      "type" : "Point", 
      "coordinates" : [ 
       -0.139088472429092, 
       51.5160229933117 
      ] 
     } 
    } 
} 

下面是我的指標

=> db.properties.getIndexes() 
[ 
    { 
     "v" : 1, 
     "key" : { 
      "_id" : 1 
     }, 
     "name" : "_id_", 
     "ns" : "cherrydoorsync.properties" 
    }, 
    { 
     "v" : 1, 
     "key" : { 
      "address.location.coordinates" : "2d" 
     }, 
     "name" : "address.location.coordinates_2d", 
     "ns" : "cherrydoorsync.properties" 
    } 
] 

但是當我運行下面的蒙戈shell命令時,我得到錯誤

db.properties.aggregate([ 
    { 
    $geoNear: { 
     near: { type: "Point", coordinates: [ -2.94379156655216, 54.8905641133194 ] }, 
     distanceField: "dist.calculated", 
     maxDistance: 2, 
     includeLocs: "dist.location", 
     num: 5 
    } 
    } 
]) 

錯誤:

assert: command failed: { 
    "ok" : 0, 
    "errmsg" : "geoNear command failed: { ok: 0.0, errmsg: \"The featureCompatibilityVersion must be 3.4 to use collation. See http://dochub.mongodb.org/core/3.4-feature-compatibility.\", code: 72, codeName: \"InvalidOptions\" }", 
    "code" : 16604, 
    "codeName" : "Location16604" 
} : aggregate failed 
[email protected]/mongo/shell/utils.js:25:13 
[email protected]/mongo/shell/assert.js:16:14 
[email protected]/mongo/shell/assert.js:370:5 
[email protected]/mongo/shell/collection.js:1319:5 
@(shell):1:1 

2017-01-20T13:41:27.914+0530 E QUERY [main] Error: command failed:  { 
    "ok" : 0, 
    "errmsg" : "geoNear command failed: { ok: 0.0, errmsg: \"The featureCompatibilityVersion must be 3.4 to use collation. See http://dochub.mongodb.org/core/3.4-feature-compatibility.\", code: 72, codeName: \"InvalidOptions\" }", 
    "code" : 16604, 
    "codeName" : "Location16604" 
} : aggregate failed : 
[email protected]/mongo/shell/utils.js:25:13 
[email protected]/mongo/shell/assert.js:16:14 
[email protected]/mongo/shell/assert.js:370:5 
[email protected]/mongo/shell/collection.js:1319:5 
@(shell):1:1 

有t他鏈接(http://dochub.mongodb.org/core/3.4-feature-compatibility)的錯誤信息,我這個鏈接,它建議設置setFeatureCompatibilityVersion to "3.4".,我運行該命令,並再次得到了一些其他錯誤

> db.adminCommand({ setFeatureCompatibilityVersion: <"3.4" }) 
2017-01-20T13:45:39.023+0530 E QUERY [main] SyntaxError: expected expression, got '<' @(shell):1:51 

請幫我解決這個錯誤。

回答

20

極品db.adminCommand({ setFeatureCompatibilityVersion: "3.4" })

+0

''db.adminCommand({setFeatureCompatibilityVersion: 「3.4」})''命令成功執行,現在的 「featureCompatibilityVersion」 錯誤刪除,將其投入另一個錯誤 '''「errmsg」:「geoNear命令失敗:{ok:0.0,errmsg:\」無法獲得查詢執行程序\「}」, \t「code」:16604, \t「codeName」:「 Location16604「''' 我檢查了這個鏈接(h ttp://stackoverflow.com/questions/30240883/mongodb-cant-get-query-executor-when-executing-geonear-aggregate)但我只有一個索引'2d'而不是'2dsphere'如本鏈接所述。 –

+0

嘗試在2dsphere索引中刪除2d。並添加您的請求'球形:true'。它應該工作:'db.properties.aggregate([ {$ geoNear:{ 附近:{類型: 「點」,座標:[-2.94379156655216,54.8905641133194]}, distanceField: 「dist.calculated」, maxDistance :2, includeLocs: 「dist.location」, 民:5,球狀:真 }} ])' –

+0

爲我工作,謝謝 – AhammadaliPK

0

使用此在蒙戈外殼

db.adminCommand({ setFeatureCompatibilityVersion: "3.4" }) 
+0

這是一樣的接受的答案。 – SymbolixAU

相關問題