Pymongo'yu içeren bir sorgunun sonucu üzerinde döngü yapmak için python için bir for döngüsü kullanıyorum. İşte kod: Ben bir soru, nasıl varolan belgenin (b
) olmayan varolan alanda geolocCountry
içine değişkeni myGeolocCountry
ekleyebilirsiniz edilir python + pymongo: for döngüsünden mongo'da varolan bir belgeye yeni bir alan ekleme
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...
?
Ben
b['geolocCountry'] = myGeolocCountry
ile çalıştı ama hiç, hatta bir hata üretmez çalışmadı.
Teşekkür
i soo bu deneyeceğim n, teşekkürler – otmezger
Çalıştı, çözümün küçük bir hata, tho. '' myGeolocCountry' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ' – otmezger