mardi 5 mai 2015

MongoDB query show all value in array property when reference database

I cannot show all`, if some value are in array property in mongo document. For example, I have some collection users, and such document:

This is collection friend

'list': [ { '_id': '123', 'name':'Charlie', 'age':50 ], }, { '_id': '234', 'name':'Micheal', 'age':32 ], }, { '_id': '345', 'name':'Alice', 'age':45 ], } ]

This is collection seft

'name':'Paul', 'age':43, 'friends': [ { '$ref': 'friend', '$id': 123}, { '$ref': 'friend', '$id': 234}, { '$ref': 'friend', '$id': 345} ],

Now, let's suppose that I want to query "show all friends of Paul" like:

{ 'name':'Paul', 'age':43, 'friendsIDs': 'friends': [ { '_id': '123', 'name':'Charlie', 'age':50 }, { '_id': '234', 'name':'Micheal', 'age':32}, { '_id': '345', 'name':'Alice', 'age':45 } ] }

Aucun commentaire:

Enregistrer un commentaire