Reputation: 321
I am new to python and mongo db, i have a dict called data and i wanna use the keys to query the database called db.
def update_db(data, db):
for key in data:
x=db.find({'label':key})
for a in x:
print a
I get the error message that find() does not exist.
Anyone can give me input on my problem ?
Upvotes: 0
Views: 280
Reputation: 236188
There is no find
method in database object. You should search documents in some collection, not in database. Database has collections like SQL database has tables. Collections have documents, like SQL tables have rows of data. E.g. if you have users collection:
def update_db(data, db):
for key in data:
users = db.users
matchedUsers = users.find({'label':key})
for user in matchedUsers:
print user
Future reading PyMongo tutorial
Upvotes: 3