我在 python 中使用 for 循环来循环使用 pymongo 的查询结果。这是代码:
from pymongo import MongoClient
connection = MongoClient()
db = connection.Test
myDocs = db.Docs.find( { "geolocCountry" : { "$exists" : False } } )
for b in myDrives:
my_lat = b['TheGpsLog'][0]['latitude']
my_long = b['TheGpsLog'][0]['longitude']
myGeolocCountry = DoReverseGeocode(lat_start,long_start)
# Here I perform a reverse geocoding, it does not matter for this example.
# The important thing is: it returns a string, like 'US', 'UK', etc...
我的问题是,如何将变量插入到现有文档()上myGeolocCountry
的非现有字段中?geolocCountry
b
我试过了
b['geolocCountry'] = myGeolocCountry
但它根本不起作用,它甚至不会产生错误。
谢谢