我試圖在我的flask
應用程序中更新PointField
upsert_one
。但它總是插入新文件。我知道問題出在我傳遞的查詢上。如何查詢PointField - MongoEngine
下面是我的模型。
class Location(db.Document):
location_name = db.StringField(required=True)
geoCoords = db.PointField()
並更新查詢。
Location.objects(geoCoords=loc["geoCoords"]).upsert_one(location_name=loc["location_name"], geoCoords=loc["geoCoords"])
#loc["geoCoords"] = [77.6309395,12.9539974]
我也試過運行get
。但是我收到以下查詢的錯誤消息"Location matching query does not exist."
。
loc = Location.objects(geoCoords=[77.6309395,12.9539974]).get()
我在我的location
集合中有以下條目。
> db.location.find()
{ "_id" : ObjectId("59c5019727bae70ad3259e67"), "geoCoords" : { "type" : "Point", "coordinates" : [ 77.6309395, 12.9539974 ] }, "location_name" : "Bengaluru" }
{ "_id" : ObjectId("59c5022d27bae70ad3259ea2"), "geoCoords" : { "type" : "Point", "coordinates" : [ 77.6309395, 12.9539974 ] }, "location_name" : "Bengaluru" }
>
我在查詢PointFiled
時找不到任何有關信息。
'upsert_one'不工作,因爲'Location.objects(geoCoords = LOC [ 「geoCoords」])''返回位置匹配查詢不exist.'。所以,'update'也一樣。 – james