我正在尝试将2dSphere索引添加到包含位置数组的Mongo Collection。这是我得到的错误:
[MongoError: insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?:
{ _id: "gjuFiwHd7ctBpgEwL",
title: "Iny orple taoland.",
locations: [
{ loc:
{ type: "Point", coordinates: [ "0.0181033", "43.8355792" ] }
}
]
}
]
我在哪里打电话:
ensureIndex({ 'locations.loc': "2dsphere" })
我做错了什么?
答案 0 :(得分:2)
对于2dsphere,点以GeoJSON格式指定。一个点由两个元素的数组给出,代表[longitude,latitude]
。您应该更改coordinates
数组。
lon
和lat
点不应该用双qoutes包裹。
应该是:
{ type: "Point", coordinates: [ 0.0181033, 43.8355792] }