Javascript MongoDB格式错误的几何体,带有geojson
使用MongoDB v2.6.5 当我尝试将geojson文档保存到db中时,我收到以下错误:Javascript MongoDB格式错误的几何体,带有geojson,javascript,node.js,mongodb,mongoose,geojson,Javascript,Node.js,Mongodb,Mongoose,Geojson,使用MongoDB v2.6.5 当我尝试将geojson文档保存到db中时,我收到以下错误: name: 'MongoError', code: 16755, err: 'insertDocument :: caused by :: 16755 Can\'t extract geo keys from object, malformed geometry?: { _id: ObjectId(\'55271b90d075728028d4c9e1\'), ..., location: [
name: 'MongoError',
code: 16755,
err: 'insertDocument :: caused by :: 16755 Can\'t extract geo keys from object, malformed geometry?: { _id: ObjectId(\'55271b90d075728028d4c9e1\'), ..., location: [ { _id: ObjectId(\'55271b90d075728028d4c9e3\'), loc: { type: "Point", coordinates: [ -105.01621, 39.57422 ] } } ] } ], status: [ "lead" ], created: new Date(1428626320406), lastName: "Doe", firstName: "John", __v: 0 }' }
我正试图使用2dsphere索引将一个点插入表中,所有这些都是通过MongooseJS管理的,如下所示
var GeoAddressSchema = new Schema({
// Only holds points.
loc: {
type: { type: String },
coordinates: []
}
});
var Lead = new Schema({
// Other fields ...
location: [GeoAddressSchema],
// ...
});
LeadAddressSchema.index({ location: '2dsphere' });
正在保存的geojson:
{ type: "Point", coordinates: [ -111.855211, 33.58513 ] }
geojson的有效性取决于:如果我将字段用引号括起来,但我不需要这样做(对于Mongo afaik也不能这样做)
有人知道为什么会失败吗?看起来是对的
参考链接
MongoDB GeoJSON:
MongoDB 2dSphere:第一个观察:您不需要在位置结构中引入
loc
路径
此外,您甚至不需要为Lead
模式中的位置
字段定义单独的模式
试试这个:
var Lead = new Schema({
// Other fields ...
location: {
type: {
type: 'String',
default: 'Point' // and optionally skip including `type: String` everywhere
},
coordinates: {
type: [Number]
}
},
// More fields ...
});
LeadAddressSchema.index({ location: '2dsphere' });
我面临的另一个问题是,在计算和测试解决方案时,2dsphere
索引变得混乱。因此,在对模式进行结构更改后,请尝试删除索引,或者更好地删除集合
> db.lead.drop(); // on the mongo console`
第一个观察:您不需要在位置结构中引入
loc
路径
此外,您甚至不需要为Lead
模式中的位置
字段定义单独的模式
试试这个:
var Lead = new Schema({
// Other fields ...
location: {
type: {
type: 'String',
default: 'Point' // and optionally skip including `type: String` everywhere
},
coordinates: {
type: [Number]
}
},
// More fields ...
});
LeadAddressSchema.index({ location: '2dsphere' });
我面临的另一个问题是,在计算和测试解决方案时,2dsphere
索引变得混乱。因此,在对模式进行结构更改后,请尝试删除索引,或者更好地删除集合
> db.lead.drop(); // on the mongo console`
第一个观察:您不需要在位置结构中引入
loc
路径
此外,您甚至不需要为Lead
模式中的位置
字段定义单独的模式
试试这个:
var Lead = new Schema({
// Other fields ...
location: {
type: {
type: 'String',
default: 'Point' // and optionally skip including `type: String` everywhere
},
coordinates: {
type: [Number]
}
},
// More fields ...
});
LeadAddressSchema.index({ location: '2dsphere' });
我面临的另一个问题是,在计算和测试解决方案时,2dsphere
索引变得混乱。因此,在对模式进行结构更改后,请尝试删除索引,或者更好地删除集合
> db.lead.drop(); // on the mongo console`
第一个观察:您不需要在位置结构中引入
loc
路径
此外,您甚至不需要为Lead
模式中的位置
字段定义单独的模式
试试这个:
var Lead = new Schema({
// Other fields ...
location: {
type: {
type: 'String',
default: 'Point' // and optionally skip including `type: String` everywhere
},
coordinates: {
type: [Number]
}
},
// More fields ...
});
LeadAddressSchema.index({ location: '2dsphere' });
我面临的另一个问题是,在计算和测试解决方案时,2dsphere
索引变得混乱。因此,在对模式进行结构更改后,请尝试删除索引,或者更好地删除集合
> db.lead.drop(); // on the mongo console`
GeoJSON在错误消息中指出,并在您的问题中发布,这两个索引对我来说都很好。您使用的是哪个版本的MongoDB?你能给出一个最简单的失败的例子吗?GeoJSON在错误消息中指出,在你的问题中发布,这两个索引对我来说都很好。您使用的是哪个版本的MongoDB?你能给出一个最简单的失败的例子吗?GeoJSON在错误消息中指出,在你的问题中发布,这两个索引对我来说都很好。您使用的是哪个版本的MongoDB?你能给出一个最简单的失败的例子吗?GeoJSON在错误消息中指出,在你的问题中发布,这两个索引对我来说都很好。您使用的是哪个版本的MongoDB?你能举一个最简单的例子吗?这是完美的。非常感谢。它还简化了我的许多代码。我真的很感激!顺便说一句,我还碰到了你提到的索引问题。我不得不放下它,然后读了一遍。这让我意识到我最初的实现是错误的。它在当地起作用。然后我把它推到一个CI环境中,发现它坏了。你能解释一下如何删除索引以及如何替换索引吗?你救了我的命,经过两天的尝试,我读到了你的答案,说删除收藏是件好事,这就是我的问题。谢谢你,这太完美了。非常感谢。它还简化了我的许多代码。我真的很感激!顺便说一句,我还碰到了你提到的索引问题。我不得不放下它,然后读了一遍。这让我意识到我最初的实现是错误的。它在当地起作用。然后我把它推到一个CI环境中,发现它坏了。你能解释一下如何删除索引以及如何替换索引吗?你救了我的命,经过两天的尝试,我读到了你的答案,说删除收藏是件好事,这就是我的问题。谢谢你,这太完美了。非常感谢。它还简化了我的许多代码。我真的很感激!顺便说一句,我还碰到了你提到的索引问题。我不得不放下它,然后读了一遍。这让我意识到我最初的实现是错误的。它在当地起作用。然后我把它推到一个CI环境中,发现它坏了。你能解释一下如何删除索引以及如何替换索引吗?你救了我的命,经过两天的尝试,我读到了你的答案,说删除收藏是件好事,这就是我的问题。谢谢你,这太完美了。非常感谢。它还简化了我的许多代码。我真的很感激!顺便说一句,我还碰到了你提到的索引问题。我不得不放下它,然后读了一遍。这让我意识到我最初的实现是错误的。它在当地起作用。然后我把它推到一个CI环境中,发现它坏了。你能解释一下如何删除索引以及如何替换索引吗?你救了我的命,经过两天的尝试,我读到了你的答案,说删除收藏是件好事,这就是我的问题。谢谢你,伙计