2

That's the query that i'm executing:

mongoexport --db solutions --collection solution3 --query "{ 'metrictimestamp': { '$gte': { '$date': '2016-03-01T00:00:00.001Z' },'$lte': { '$date': '2016-03-29T23:59:59.000Z' }}}"--out a.json

but i keep on getting this error:

Failed: error parsing query as Extended JSON: invalid JSON input

I've tried to invert the quotes, and all the solutions that i saw on Use mongoexport with a --query for ISODate

JediJesus
  • 329
  • 1
  • 9
  • Is it because there are no space after " before - - – Gibbs Aug 06 '20 at 12:50
  • mongoexport -d solutions -c solution3 -q "{ 'metrictimestamp' : { '$gte': new Date('2018-01-10T00:00:00.001Z'), '$lte': new Date('2018-01-10T00:00:00.001Z')}}" --out a.json – JediJesus Aug 06 '20 at 13:05
  • is that what you said? – JediJesus Aug 06 '20 at 13:05
  • yes same error. – JediJesus Aug 06 '20 at 13:07
  • Please post a sample document you are trying to export. – prasad_ Aug 06 '20 at 13:41
  • { "_id" : ObjectId("5ea79b5da8d460059a5f58eb"), "direction" : 0, "metrictimestamp" : ISODate("2018-02-01T02:59:55Z"), "odometer" : 19030291, "routecode" : 0, "speed" : 0, "deviceid" : 8155064, "vehicleid" : 34489, "location" : { "type" : "Point", "coordinates" : [ -3.878595, -38.533493 ] } } – JediJesus Aug 06 '20 at 14:41

1 Answers1

3

After a lot of trial and run, I found it works perfect by passing query through a file instead of command line.

create a file query.json and put your query in normal json format, with double quotes.

{"metrictimestamp":{"$gte":{"$date":"2016-03-01T00:00:00.001Z"},"$lte":{"$date":"2016-03-29T23:59:59.000Z"}}}

and then run the command passing the file to --queryfile instead of --query

mongoexport --db solutions --collection solution3 --queryfile query.json --out a.json