Mongodb featureCompatibilityVersion必须为3.4才能使用排序规则

Mongodb featureCompatibilityVersion必须为3.4才能使用排序规则,mongodb,geospatial,Mongodb,Geospatial,我需要在我的网站中集成英里/距离搜索,我正在使用MongoDB地理空间索引,但是,我得到了一些,无法解决。下面是我正在使用的模式和命令 => db.properties.findOne({},{address:1}) { "_id" : ObjectId("585b909c870d907845b695fd"), "address" : { "postcode" : "W1D 1NN", "address1" : "Essence",

我需要在我的网站中集成英里/距离搜索,我正在使用MongoDB地理空间索引,但是,我得到了一些,无法解决。下面是我正在使用的模式和命令

=> 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"
    }
]
然而,当我在MongoShell中运行以下命令时,我得到一个错误

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

断言:命令失败:{ “ok”:0, “errmsg”:“geoNear命令失败:{ok:0.0,errmsg:\”要使用排序规则,featureCompatibilityVersion必须为3.4。请参阅 .\”,代码:72, 代号:\“无效选项\“}”, “代码”:16604, “代号”:“位置16604” }:聚合失败 _getErrorWithCode@src/mongo/shell/utils.js:25:13 doassert@src/mongo/shell/assert.js:16:14 断言。commandWorked@src/mongo/shell/assert.js:370:5 DBCollection.prototype。aggregate@src/mongo/shell/collection.js:1319:5 @(外壳):1:1

.\”,代码:72, 代号:\“无效选项\“}”, “代码”:16604, “代号”:“位置16604” }:聚合失败: _getErrorWithCode@src/mongo/shell/utils.js:25:13 doassert@src/mongo/shell/assert.js:16:14 断言。commandWorked@src/mongo/shell/assert.js:370:5 DBCollection.prototype。aggregate@src/mongo/shell/collection.js:1319:5 @(外壳):1:1

错误消息中有一个链接(),我遵循该链接,它建议将
setFeatureCompatibilityVersion设置为“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:需要
db.adminCommand({setFeatureCompatibilityVersion:“3.4”})

在mongo shell中使用它

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

db.adminCommand({setFeatureCompatibilityVersion:“3.4”})
命令成功执行,现在“featureCompatibilityVersion”错误被删除,并引发另一个错误
“errmsg”:“geoNear命令失败:{ok:0.0,errmsg:\“无法获取查询执行器”},“code”:16604,“codeName”:“Location16604”
我检查了这个链接()但是我只有一个索引
2d
而不是这个链接中提到的
2dsphere
。请尝试删除2dsphere索引上的2d。然后添加您的请求
sphere:true
。它应该可以工作:
db.properties.aggregate([{$geoNear:{type:{Point],坐标:[-2.94379156655216,54.8905641133194]},distance字段:“dist.computed”,maxDistance:2,includeLocs:“dist.location”,num:5,sphere:true}])
db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )