mongodb - pymongo: Best way to query by reference? -


i have bunch of paper documents in papers collection. each paper has 1 dbref person document. person property in paper document dbref correct person

person

{'name' : 'person a', 'slug' : 'pa'}, {'name' : 'person b', 'slug' : 'pb'} 

paper

{'name' : 'paper 1', 'person': dbref}, {'name' : 'paper 2', 'person': dbref}, {'name' : 'paper 3', 'person': dbref} 

i create query returns papers reference person (slug=='pa'). tried filtering in query, , failed @ map reduce statement. best way handle in pymongo?

this query returns no results

for paper in db['papers'].find({'person.slug' : 'pa'}):      print paper 

map reduce returns 0 results

mapper = code("""                 function () {                 if (this.person.slug == slug) {                         emit (this, 1);                         }                 }     """)      reducer = code("""         function (key, values) {             return key;         }     """)     result = db['papers'].map_reduce(mapper, reducer, "myresults",  scope={'slug' : 'pa'})     doc in result.find():         print doc 

it looks though can this, , can't use other properties

for paper in db['papers'].find({'person.$id' : person['_id']}): 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -