使用MongoDB 2dsphere存储GEOJSON并在lat / lng的某些商店中我一直收到以下错误:
{
"code": 16755,
"index": 0,
"errmsg": "Can't extract geo keys: { _id: ObjectId('586ff135b79aa00b84181bfb'), name: \"Austin\", slug: \"Austin\", description: \"\", twitter: \"\", facebook: \"\", instagram: \"\", author: ObjectId('57b60fed8620b56af460d5c5'), tags: [], created: new Date(1483731253640), location: { address: \"Austin, TX, United States\", coordinates: [ 30.267153, -97.74306079999997 ], type: \"Point\" }, __v: 0 } longitude/latitude is out of bounds, lng: 30.2672 lat: -97.7431",
"op": {
"name": "Austin",
"slug": "Austin",
"description": "",
"twitter": "",
"facebook": "",
"instagram": "",
"author": "57b60fed8620b56af460d5c5",
"_id": "586ff135b79aa00b84181bfb",
"tags": [
],
"created": "2017-01-06T19:34:13.640Z",
"location": {
"address": "Austin, TX, United States",
"coordinates": [
30.267153,
-97.74306079999997
],
"type": "Point"
},
"__v": 0
}
}
我似乎无法弄清楚它为什么不喜欢某些lat / lng坐标。
以下是我的位置字段架构:
location: {
type: { type: String, default: 'Point' },
coordinates: [Number],
address: String
},
并将其编入索引为2dsphere
:
storeSchema.index({ location: '2dsphere' });
我能看到的唯一奇怪的是错误信息:
longitude/latitude is out of bounds, lng: 30.2672 lat: -97.7431",
lat / lng缩短了我输入的内容 - 不确定是否与它有任何关系。
答案 0 :(得分:26)
[lng, lat]
,而不是[lat,lng]
,就像这个世界上的其他一切一样。
:|
答案 1 :(得分:3)
以下是我如何修复问题而无需交换[lat,lng]
序列。
您的代码中某处正在调用ensureIndex
。而不是打电话(就像我以前那样)......
collection.ensureIndex({ "location": "2dsphere" });
请改用以下内容......
collection.ensureIndex({ "location.coordinates":"2d"});
这完全消除了运行时的错误,并且不需要大量的数据重构。