Mongodb 物业的顺序是否重要?

Mongodb 物业的顺序是否重要?,mongodb,insert,geojson,2dsphere,Mongodb,Insert,Geojson,2dsphere,我有一个具有以下索引的集合 [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "bs.locations" }, { "v" : 1, "key" : { "location" : "2dsphere" }, "n

我有一个具有以下索引的集合

[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "bs.locations"
    },
    {
        "v" : 1,
        "key" : {
            "location" : "2dsphere"
        },
        "name" : "location_2dsphere",
        "ns" : "bs.locations",
        "2dsphereIndexVersion" : 2
    }
]
我可以插入以下文件:

db.locations.insert({ "location" : {"coordinates" : [ 6.982654547382455, 46.88414220428685 ], "type" : "Point", "test":1.0} })
db.locations.insert({ "location" : {"test":1.0, "coordinates" : [ 6.982654547382455, 46.88414220428685 ], "type" : "Point"} })
但当我尝试插入此文档时:

db.locations.insert({ "location" : {"coordinates" : [ 6.982654547382455, 46.88414220428685 ], "type" : "Point", "test":1.0} })
db.locations.insert({ "location" : {"test":1.0, "coordinates" : [ 6.982654547382455, 46.88414220428685 ], "type" : "Point"} })
我得到以下错误:

WriteResult({
    "nInserted" : 0,
    "writeError" : {
        "code" : 16755,
        "errmsg" : "Can't extract geo keys: { _id: ObjectId('5566050507c10c31ce7214af'), location: { test: 1.0, coordinates: [ 6.982654547382455, 46.88414220428685 ], type: \"Point\" } }  Point must only contain numeric elements"
    }
})
我的问题是,我错过了什么?我的错误是什么


我使用MongoDB v3.0.1版

根据MongoDB手册,在2dsphere索引上有一些字段限制。限制条件如下:

2dsphere索引字段限制具有2dsphere索引的字段必须 以坐标对或GeoJSON数据的形式保存几何体数据。如果 尝试在二维球体中插入包含非几何图形数据的文档 索引字段,或在 索引字段包含非几何体数据,操作将失败

要成为
GeoJSON
对象,对象应根据以下结构包含类型坐标字段:

{ type: "<GeoJSON type>" , coordinates: <coordinates> }
{type:,坐标:}
由于
location
被索引为
2dsphere
,您的第一个插入查询将得到满足,因为它包含文档开头的一对。但在第二种情况下,文档结构违反了限制。它从一开始就需要类型坐标


根据MongoDB手册,这是导致insert语句出现这种情况的唯一逻辑原因