I use the below mongodump code to dump records based on a date, in an .sh
file:
$MONGODUMP_PATH -h $MONGO_HOST:$MONGO_PORT
-d $MONGO_DATABASE -c $MONGO_COLLECTION
--queryFile subset.json
subset.json
:
{ "TheDate": { "$gte": new Date(new Date().setDate(new Date().getDate() - 1)) } }
That does not work, and produces an error:
Failed: error parsing query as json: invalid character '.' after constructor argument
But if I change subset.json
to include a static date value, it works:
{ "TheDate": { "$gte": ISODate("2016-06-14T07:12:23.051Z") } }
Where ISODate("2016-06-14T07:12:23.051Z")
equals new Date(new Date().setDate(new Date().getDate() - 1))
as previously.
But I would need a dynamic value for date, as in the first case. Have been looking for a solution online but cant find any...
Any ideas? Best Regards