MongoDB:地理空间索引数组格式不正确
在尝试设置以在MongoDB上使用地理空间索引时,我遇到了错误消息,即位置数组的格式不正确.
While trying to setup to use the Geospatial Index on MongoDB, I run into the error message that the location array is not in the correct format.
这是我的收藏集测试".
This is my collection "test".
{
"_id" : ObjectId("4f037ac176d6fdab5b00000a"),
"CorporateId" : "XYZ12345",
"Places" : [
{
"Location" : {
"Longitude" : "50.0",
"Latitude" : "50.0"
},
"ValidFrom" : "2011-11-01 00:00:00",
"ValidTo" : "2021-12-31 00:00:00",
"itemCount" : "1"
}
]
}
一旦我运行此代码.
db.test.ensureIndex({"Places.Location": "2d"});
我收到此错误消息
预期的位置对象,位置数组的格式不正确
location object expected, location array not in correct format
我的假设是长/短需要是一个数字. 当前它是一个对象.
My assumption is that the Long/Lat needs to be a number. Currently it is an object.
typeof db.test.Places.Location.Longitude -> Object
typeof db.test.Places.Location -> Object
我的问题是,由于我还是MongoDB的新手,所以我真的不知道如何以最佳方式解决此问题.
My problem is that since I am still quite new to MongoDB, I don't really know how to approach this problem in the best way.
在传递字符串时,Mongodb期望坐标的数字.
Mongodb expects numbers for the coordinates while you passed in a string.
"Location" : {
"Longitude" : 50.0, // <<<<<<<<<<<<<< use numbers instead
"Latitude" : 50.0
},
请参阅 http://www.mongodb.org/display/DOCS/Geospatial+Indexing 详细信息.