Is it possible to use $nin and $in on the variable basis in mongoose find parameters?
Like if suppose am getting req.params.take = True then I want the parameter check to be
Document.find({_id : {
$in:[PreDefinedArray]
}}
or else if it's not present I want it to be
Document.find({_id : {
$nin:[PreDefinedArray2]
}}
Not this can be for many populate statements using a match, so I cannot use if else or any other conditioning statement for the same to have multiple types of queries. Can it be done with some other technique? As I tried replacing $in and $nin with string variables like this
var selector = (check) ? ("$in") : ("$nin");
Document.find({_id : {
selector : [PreDefinedArray2]
}}
but it didn't work.