Reputation: 43
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.
Upvotes: 4
Views: 18433
Reputation: 1458
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})
Upvotes: 4