mongodbmongoexport

Keep on getting an error on the json format of my mongoexport


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


Solution

  • 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