2017-01-20 12 views
9

Tôi cần phải tích hợp dặm/tìm kiếm khoảng cách trong trang web của tôi và tôi đang sử dụng chỉ số không gian địa lý MongoDB, tuy nhiên tôi đang nhận được một số và không thể giải quyết. Dưới đây là lược đồ và lệnh của tôiCác featureCompatibilityVersion phải 3.4 để sử dụng đối chiếu

=> 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 
      ] 
     } 
    } 
} 

Dưới đây là chỉ số của tôi

=> 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" 
    } 
] 

Tuy nhiên khi tôi chạy sau lệnh trong shell Mongo, tôi đang nhận lỗi

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

lỗi:

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 

Có t ông liên kết (http://dochub.mongodb.org/core/3.4-feature-compatibility) trong thông báo lỗi và tôi đi theo liên kết đó, nó gợi ý để thiết lập setFeatureCompatibilityVersion to "3.4"., tôi chạy lệnh đó và một lần nữa nhận được một số lỗi khác

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

Xin hãy giúp tôi giải quyết lỗi này.

Trả lời

20

Cần db.adminCommand({ setFeatureCompatibilityVersion: "3.4" })

+0

'' db.adminCommand ({setFeatureCompatibilityVersion: "3.4"}) ' 'lệnh thực hiện thành công, bây giờ "featureCompatibilityVersion" lỗi lấy ra và nó ném một lỗi khác '' '" errmsg ":" lệnh geoNear không thành công: {ok: 0.0, errmsg: \ "không thể nhận được truy vấn thực thi \"} ", \t" mã ": 16604, \t" codeName ":" Location16604 "' '' tôi đã kiểm tra liên kết này (h ttp: //stackoverflow.com/questions/30240883/mongodb-cant-get-query-executor-when-executing-geonear-aggregate) nhưng tôi chỉ có một chỉ mục '2d' không phải' 2dsphere' như đã đề cập trong liên kết này. –

+0

Thử xóa 2d trên chỉ mục 2dsphere. Và thêm vào yêu cầu của bạn 'hình cầu: true'. Nó nên công trình: 'db.properties.aggregate ([ { $ geoNear: { gần: {type: "Point", phối: [-2,94379156655216, 54,8905641133194]}, distanceField: "dist.calculated", maxDistance : 2, includeLocs: "dist.location", num: 5, hình cầu: true } } ]) ' –

+0

làm việc cho tôi, cảm ơn – AhammadaliPK

0

Sử dụng này trong Mongo shell

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

Điều này giống như câu trả lời được chấp nhận. – SymbolixAU

Các vấn đề liên quan