Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB/mongoose queries and the $in operator

A question about MongoDB/mongoose queries using $in http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24in

If I do a query where both the target field AND the $in field have multiple values, is there a way to know which target/$in field elements were matched in a returned argument?

Eg if I have a bunch of documents like this

doc1 = { name : Abe, children : [Betty, Claire, Donald, Eamon] }

and i set up a query

Model.find( { children : { $in : [Ann, Betty, Clive] } })

if i get the result doc1 above, is there any way i can know (without iterating through the arrays manually) which target element and which $in element were matched? so in the case above, how could I access the fact that doc1 was chosen because it matched 'Betty'? Thanks in advance!

like image 547
Petrov Avatar asked Oct 23 '22 23:10

Petrov


1 Answers

You must manually check the mongoose doc.

like image 200
aaronheckmann Avatar answered Oct 26 '22 21:10

aaronheckmann