Python Mongoengine PointField提供了预期的位置对象,位置数组格式不正确错误
我有一个模型如下:Python Mongoengine PointField提供了预期的位置对象,位置数组格式不正确错误,python,mongodb,pymongo,mongoengine,nosql,Python,Mongodb,Pymongo,Mongoengine,Nosql,我有一个模型如下: class Station(Document): location = PointField() station = Station() station.location = { "type": "Point", "coordinates": [ 81.4471435546875, 23.61432859499169 ] } station.save() 尝试按如下方式写入数据: class Station(Do
class Station(Document):
location = PointField()
station = Station()
station.location = {
"type": "Point",
"coordinates": [
81.4471435546875,
23.61432859499169
]
}
station.save()
尝试按如下方式写入数据:
class Station(Document):
location = PointField()
station = Station()
station.location = {
"type": "Point",
"coordinates": [
81.4471435546875,
23.61432859499169
]
}
station.save()
但是,这会导致错误无法保存文档(需要位置对象,位置数组格式不正确)
Mongoengine文档说这样的词典应该没问题。我错过了什么 我曾经遇到过类似的问题,在我的例子中,这是因为我使用GeoPointField构建第一个原型,然后在不删除或迁移数据库的情况下移动到PointField,对我来说,并且因为数据库中只有虚拟数据,所以在启动fresh my db完成删除后,问题就解决了。我希望它能有所帮助。我首先使用了GeoPointField,然后转换为PointField。我在集合中删除了数据,但不是集合本身,ehich造成了这个问题
删除集合解决了问题。在将一些数据从
GeoPointField
转换为PointField
(使用MongoEngine)后,我遇到了类似的问题
这是由于存在两个索引造成的。一个用于地质点域
,另一个用于点域
。我放弃了第一个索引,一切都很顺利
您可以使用
db.collection.getIndexes()检查索引
然后使用db.collection.dropIndex(“index\u name”)删除索引,确保已安装最新版本的mongoengine。适用于0.8.4