Question

I have a collection of records that I normally want all results for, however in some cases the user will provide a list of IDs to exclude from the results.

Is there a way to perform a query with mongoose, and give it an array of IDs to exclude from the results?

Was it helpful?

Solution

Sure, it is as easy as this:

db.coll.find( { "_id": { "$nin": [ 1, 2, 3 ] } } )

In Mongoose it would be:

Model.where( "_id" ).nin( [ 1, 2, 3 ] )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top