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 ] )
Frage
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?
Lösung
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 ] )