简体   繁体   中英

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

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.

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})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM