I have a shell script with a query to get some information in a MongoDB
database and I'm having a problem to make a more detailed query.
For example, if the query is simple it works, like this:
exec_mongo='mongo -u USER HOST/MYDATABASE -pPASSWORD --authenticationDatabase admin'
query='printjson(db.MYDATABASE.find().toArray())'
res=$($exec_mongo --eval $query)
echo $res >> results.csv
But, if I add some parameters, like "AND" or "OR", doesn't work:
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 >> results.csv
I think maybe this is because of the $and
, but not sure about. Can anyone help me with this, please?
Note: the code above works if I type directly in mongodb access (mongo shell
).
Thanks in advance.