2017-01-20 10 views
9

Web sitemde mil/mesafe aramasını bütünleştirmem gerekiyor ve mongodb geospatial endeksler kullanıyorum, ancak biraz alıyorum ve çözemiyorum. Aşağıda benim şema ve komut AşağıdaÖzellikCompatibilityVersion, harmanlamayı kullanmak için 3.4 olmalıdır

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

olduğu zaman endeksleri Ancak

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

i Mongo kabuğunda çalışma aşağıdaki komutu zaman, ben alıyorum hata

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

hatası:

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 

Ben o komutu çalıştırmak ve yeniden

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

bana bu hatayı çözmek yardım edin diğer bazı hata alıyorsanız, setFeatureCompatibilityVersion to "3.4". ayarlamak için önermek, o hata mesajında ​​(http://dochub.mongodb.org/core/3.4-feature-compatibility) bağlamak ve ben bu bağlantıyı takip edin.

cevap

20

İhtiyaç db.adminCommand({ setFeatureCompatibilityVersion: "3.4" })

+0

'db.adminCommand kabuk ({setFeatureCompatibilityVersion: "3,4"})' 'komutu artık "featureCompatibilityVersion" hata çıkarıldı ve atmak, başarılı bir şekilde çalıştırır Başka bir hata '' 'errmsg ':" geoNear komutu başarısız oldu: {ok: 0.0, errmsg: \ "sorgu yürütücüsü \"} ", \t" kodu ": 16604, \t" codeName ":" Location16604 "' bu bağlantıyı kontrol ettim (h) ttp: //stackoverflow.com/questions/30240883/mongodb-cant-get-query-executor-when-executing-geonear-aggregate) ancak bu linkte belirtildiği gibi sadece bir indeks '2d' '2dsphere' değil. –

+0

2dsphere dizinindeki 2d'yi kaldırmayı deneyin. Ve isteğinize 'küresel: gerçek' ekleyin. 'Db.properties.aggregate ([ { $ geoNear: { yakın: {türü: "Nokta", koordinatları: Bu eserler should [-2,94379156655216, 54,8905641133194]}, distanceField: "dist.calculated", maxDistance : 2, includeLocs: "dist.location", num: 5, küresel: gerçek} } ]) ' –

+0

Bu kabul edilen yanıt aynıdır benim için teşekkürler – AhammadaliPK

0

kullanımı Mongo'da bu

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

çalıştı. – SymbolixAU