I am a new beginner of mongodb. I want to export some data in recent hours from my databases. So, I think I need to write mongoexport command and include date range in --query
options to do it.
I write a bash file like this and try to run it:
#!/bin/bash
mongoexport --host localhost:27017 --db copy --collection txt --csv --fields x1,x2,x3...,date --query '{ "date" : {$gt:new Date(new Date() - 1000*60*60*3)} }' --out home/data.csv
But I get the results says:
connected to: localhost:27017
assertion: 16619 code FailedToParse: FailedToParse: Expecting '}' or ',': offset:25 of:{ "date" : {$gt:new Date(new Date() - 1000*60*60*3)} }
It sees connect to localhost but cannot output the data. If I remove --query
option, this can run successfully and get the whole data, but I must need the query to subset the data in recently 3 hours.
Any ideas and help will be highly appreciated. Thank you and Best.