4

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.

1
  • Maybe provide some code, your table structure, etc? Commented Apr 20, 2012 at 8:50

1 Answer 1

4

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})
Sign up to request clarification or add additional context in comments.

2 Comments

I tried doing this, collection = db['student_details'] query = "%s" % option.uidfile results = collection.find({"user_id":query}) for i in results: print i
Unfortunately the tutorial link is no longer valid.

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.