I have a mongo collection with several documents, suppose the following (suppose Tom had two teachers for History in 2012 for any reason)
{ "name" : "Tom" "year" : 2012 "class" : "History" "Teacher" : "Forester" } { "name" : "Tom" "year" : 2011 "class" : "Math" "Teacher" : "Sumpra" } { "name" : "Tom", "year" : 2012, "class" : "History", "Teacher" : "Reiser" }
I want to be able to query all the classes that Tom has ever had, although Tom had several History classes with several teachers, I just want the query to have the minimum number of documents, Tom in all of them, and History "appears once, not the result of a query that contains several documents with the repetition of" History ".
I looked: http://mongoengine-odm.readthedocs.org/en/latest/guide/querying.html
and want to try something like:
student_users = Students.objects(name = "Tom", class = "some way to say distinct?")
Although it does not seem to be documented. If this is not the syntactically correct way to do this, is it possible in mongoengine, or is there some way to execute with some other library like pymongo? Or do I need to request all documents with Tom, and then do some post processing to get unique values? The syntax will be appreciated for any occasion.
Rollingo
source share