mongo query in python
18,355
You should take a look at the tutorial here
http://api.mongodb.org/python/2.0/tutorial.html
But if you had collection "student_details" opened in python you would query:
collection.find({"userID" : user_id})
Author by
Admin
Updated on June 27, 2022Comments
-
Admin almost 2 years
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
users={ _id :Object(###), name:"", standard:"" .. .. .. } student_details={ _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
ouput:
<pymongo.cursor.Cursor object at 0x95c910c>
Thanks in advance.
-
Admin about 12 yearsI tried doing this, collection = db['student_details'] query = "%s" % option.uidfile results = collection.find({"user_id":query}) for i in results: print i