0

I am trying to export data updated in mongodb in last 7 days with mongoexport command from linux terminal I am using the following command

mongoexport --db your_database --collection your_collection --query '{ "updatedAt": { "$gt": new Date(new Date().getTime() - (7 * 24 * 60 * 60 * 1000)) } }' --out output.json

but it's throwing error not is not a validjson invalid character '.' after constructor argument

  • ` new Date` is a javascript function, available in mongo shell. It dynamically gets system time and converts it to ISODate clientside. --query parameter is just a string. mongoexport doesn't have any of javascript helpers of mongosh. You need to manually calculate the time and pass it as a value to the filter. See the duplicate for the correct syntax. – Alex Blex Aug 30 '23 at 12:12

0 Answers0