Mongoengine PointField gives location object expected, location array not in correct format error

試著忘記壹切 提交于 2019-12-10 19:12:30

问题


I have a model as follows:

class Station(Document):
    location = PointField()

Trying to write data as follows:

station = Station()
station.location = {
    "type": "Point",
    "coordinates": [
      81.4471435546875,
      23.61432859499169
    ]
  }
station.save()

However this gives the error Could not save document (location object expected, location array not in correct format)

Mongoengine documentation says such a dictionary should be OK. What am I missing here?


回答1:


I face similar problem once, in my case it happens because i use GeoPointField to build the first prototype then move to PointField without dropping or migrating my database, for me, and because there were just dummy data in the db, the problem solves just after starting fresh my db doing a complete drop. I hope it can be helpful.




回答2:


I had a similar issue after converting some data from GeoPointField to PointField (using MongoEngine).

It was caused by the presence of two indexes. One for GeoPointFIeld and the other for PointField. I dropped the first index and everything went fine.

You can check your indexes with db.collection.getIndexes(); and then drop the index with db.collection.dropIndex("index_name")




回答3:


I had used GeoPointField first and then converted to PointField. I had dropped the data in the collection but not the collection itself, ehich created this problem.

Dropping the collection solved the issue.



来源:https://stackoverflow.com/questions/20097668/mongoengine-pointfield-gives-location-object-expected-location-array-not-in-cor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!