Thursday 20 April 2017

MongoDB/Mongoose query to filter all the value in an array based on their presence in a collection

I have an array lets say [1,2,3] and a collection called 'Numbers' and it has a field called 'value'. I need to retain all the values in the array which are present against the 'value' field in any document in the collection.

Example,

Test array - [1,2,3]
Numbers collection - [{value: 1}, {value: 3}]
Result should be - [1,3]

Result is that way because '2' was not present against 'value' field in any documents within 'Numbers' collection.

How do i do this?



via user3807940

No comments:

Post a Comment