mongodb FindAndModify - update data
I have this already in the MongoDB collections.
{ "_id" : ObjectId("4e677efce88c7f0718000000"), "ptbn" : "indl000000001", "tbucode" : "5649", "district" : "west", "dcode" : "110048", "tbu" : "super clinic", "state" : "开发者_开发百科delhi" }
I am unable to understand how to work with FindAndModify
from MongoDb
I am working on MongoDb 1.8
I just want to modify the 'state' from delhi to goa, and 'district' from west to north.
How do I modify all entries EXCEPT 'ptbn' in Python-2.6
This is what I've tried so far:
connection = Connection('localhost', 27017)
db = connection.health
tc = db.tc_basic
basic = {'state' : state,
'district' : district,
'Dcode' : Dcode,
'tbu' : tbu,
'tbucode' : tbucode,
'ptbn' : ptbn
}
tc.save(basic)
You don't actually need findAndModify
for this. A simple update()
will do the trick.
db.tc_basic.update({'_id':ObjectId("...")}, {'$set': {'state': 'goa', 'district': 'north'}})
For more details on what you can do with update()
see: http://www.mongodb.org/display/DOCS/Updating
精彩评论