python - PyMongo and Mongodb: using update() -
i trying use pymongo update existing index:
#!/usr/bin/env python import pymongo pymongo import mongoclient client = mongoclient() db = client.alfmonitor tests = db.tests post = { 'name' : 'blah', 'active' : true, 'url' : 'http://www.google.com', } tests.insert(post) tests_list = db.tests.find({'active':true, 'name':'blah'}) test in tests_list: test['active'] = false test.update( test, ) print '====================================================' test in db.tests.find(): print test #<- when print out these, active=true still showing
i've been trying follow documentation , examples have seen on none of them seem working me. can explain i'm doing wrong here?
thanks!
use (don't forget add multi=true
if want update all matches):
db.tests.update({'active':true, 'name':'blah'}, {'$set': {'active': false}}, multi=true)
why code isn't working:
for test in tests_list: # test of dict type test['active'] = false # calling method of dict type # adds values dictionary test dictionary test, # nothing goes database test.update( test, )
Comments
Post a Comment