title: Passing bash shell variables into a mongo shell command
body: <p>I am trying to execute a bash shell that calls the mongo shell with a command created dynamically. The bash shell looks like this:</p>
  
  <pre><code>#!/bin/bash
  
  TODAY=`date '+%Y-%m-%d'`
  
  CMD=" 'printjson(db.collection.aggregate([{$match:{processedtime:{$gte:\"$TODAY"}}},{$project:{_id:$field",count:{$sum:1}}}]))'"
  
  echo "CMD: $CMD"
  
  mongo host/mdb --eval $CMD
  </code></pre>
  
  <p>Note the processedtime field in the collection is a sting value formatted as an ISODate object.</p>
  
  <p>When executed as a bash shell I get an "Unexpected token ILLEGAL" error. If I execute the command echoed to the screen I get the desired results.</p>
  
  <p>My question is, Is there a way to pass in shell defined variables into the mongo shell and if there is what do I need to change to do this?</p>