title: Shell script query for MongoDB using AND/OR
body: <p>I have a shell script with a query to get some information in a <code>MongoDB</code> database and I'm having a problem to make a more detailed query.</p>
  
  <p>For example, if the query is simple it works, like this:</p>
  
  <pre><code>exec_mongo='mongo -u USER HOST/MYDATABASE -pPASSWORD --authenticationDatabase admin'
  
  query='printjson(db.MYDATABASE.find().toArray())'
  
  res=$($exec_mongo --eval $query)
  
  echo $res &gt;&gt; results.csv
  </code></pre>
  
  <p>But, if I add some parameters, like "AND" or "OR", doesn't work:</p>
  
  <pre><code>exec_mongo='mongo -u USER HOST/MYDATABASE -pPASSWORD --authenticationDatabase admin'
  
  query='printjson(db.MYDATABASE.find($and: [ {DATE:"2018"}, {NAME:"TEST"} ]).toArray())'
  
  res=$($exec_mongo --eval $query)
  
  echo $res &gt;&gt; results.csv
  </code></pre>
  
  <p>I think maybe this is because of the <code>$and</code>, but not sure about. Can anyone help me with this, please?</p>
  
  <p><strong>Note:</strong> the code above works if I type directly in mongodb access (<code>mongo shell</code>).</p>
  
  <p>Thanks in advance.</p>