Newbie in mongodb/python/pymongo. My mongodb client code works OK. Here it is :
db.meteo.find().forEach( function(myDoc) {
db.test.update({"contract_name" : myDoc.current_observation.observation_location.city},
{ $set: { "temp_c_meteo" : myDoc.current_observation.temp_c ,
}
},
{upsert:false,
multi:true})
})
this adds temp_c_meteo column to all documents in my test collection, when contract_name (from test collection) is equal to current_observation.observation_location.city (from meteo collection). And that's what i want!
But, i would like this to work the same in Python. Python 2.7-pymongo 2.6.3 is installed. But also Python 2.4.6 (64-bit) and 3.4.0 (64-bit).
Here is a part of the Python script :
[...]
saveInDB:
#BE connected to MongoDB client
MDBClient = MongoClient()
db = MDBClient ['test']
collection = db['infosdb']
[...]
meteos = collectionMeteo.find()
for met in meteos:
logging.info('DEBUG - Update with meteo ' + met['current_observation']['observation_location']['city'])
result = collection.update_many( {"contract_name" : met['current_observation']['observation_location']['city']},
{
"$set": {"temp_c_meteo" : met['current_observation']['temp_c']}
})
And there is the error i get : ==> [06/21/2016 10:51:03 AM] [WARNING] : 'Collection' object is not callable. If you meant to call the 'update_many' method on a 'Collection' object it is failing because no such method exists.
I read this problem could be linked to some pymongo release ("The methods save and update are deprecated", that's why i try to use update_many) but not sure et how can i make this work? Thanks