0

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 ?

2
  • 1
    You should search in collection, not in db Commented Apr 28, 2015 at 10:15
  • 1
    A collection is mongo's "version" of a table. You need to query against the actual collection and not the database. db.collection_name.find() Commented Apr 28, 2015 at 10:16

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.