I have created a CRON job that takes backup of database everyday.
The script has a command of Mongodump with a condition to dump the records that are 7 days old.
The script runs fine until I added the --query parameter into the mongodump command.
mongodump [host, port and dbparams] --query "{_id: {\$lt: ObjectId(Math.floor(new Date(Date.now() - 86400000*7)/1000).toString(16) + '0000000000000000')}}"
An error thrown because of the --query, which says:
assertion: 16619 code FailedToParse: FailedToParse: Expecting quoted string: offset:21
So what is the correct way to integrate this query into the script?
'$lt'instead of\$lthelp?'$lt'without'\'gives error'First character in field must be [A-Za-z$_]: offset:7'. I have added'\'to escape the$.