title: NodeJs - Using $nin and $in programmatically based on input data
body: <p>Is it possible to use $nin and $in on the variable basis in mongoose find parameters?</p>
  
  <p>Like if suppose am getting req.params.take = True then I want the parameter check to be</p>
  
  <pre><code>Document.find({_id : {
    $in:[PreDefinedArray]
  }}
  </code></pre>
  
  <p>or else if it's not present I want it to be</p>
  
  <pre><code>Document.find({_id : {
    $nin:[PreDefinedArray2]
  }}
  </code></pre>
  
  <p>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</p>
  
  <pre><code>var selector = (check) ? ("$in") : ("$nin");
  
  Document.find({_id : {
    selector : [PreDefinedArray2]
  }}
  </code></pre>
  
  <p>but it didn't work.</p>