我需要在我的网站中整合英里/距离搜索,并且我正在使用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
请帮我解决这个错误。
''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'如本链接所述。 –
尝试在2dsphere索引中删除2d。并添加您的请求'球形:true'。它应该工作:'db.properties.aggregate([ {$ geoNear:{ 附近:{类型: “点”,坐标:[-2.94379156655216,54.8905641133194]}, distanceField: “dist.calculated”, maxDistance :2, includeLocs: “dist.location”, 民:5,球状:真 }} ])' –
为我工作,谢谢 – AhammadaliPK