Ankita Ankita - 1 year ago 142
Python Question

mongo query in python

I have a command line argument user_id as --uid.

I want to access the record of that particular user_id from another collection "student_details" in python.

As I am new to mongoDB, I would like to get the answer for my particular query

_id :Object(###),

user_id:"", -----> referenced

I tried doing this,

collection = db['student_details']
query = "%s" % option.uidfile
results = collection.find({"user_id":query})

print results


<pymongo.cursor.Cursor object at 0x95c910c>

Thanks in advance.

Answer Source

You should take a look at the tutorial here
But if you had collection "student_details" opened in python you would query:

collection.find({"userID" : user_id})
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download