get distinct items in a collection if other item is not null

Posted by Anurag Sharma on Stack Overflow See other posts from Stack Overflow or by Anurag Sharma
Published on 2013-07-02T11:02:40Z Indexed on 2013/07/02 11:05 UTC
Read the original article Hit count: 236

Filed under:
|

I have a collection like this

{
Country : 'XYZ'
Books : [
         {"name" : "book1", "url" : "book1url", "auth_email" : "emailid1"},
         {"name" : "book2", "url" : "book2url", "auth_email" : "emailid2"},
         {"name" : "book3", "url" : "book3url", "auth_email" : "emailid3"},
         {"name" : "book4", "url" : "book4url", "auth_email" : "emailid4"}
         ..........................................
       ]

}

I want to extract distinct 'Books.name' and corresponding 'Books.email' only if 'Books.email' is not = ''

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about pymongo