Search code examples
jsonmongodbmongoexport

query argument of mongoexport


What is the right format of query argument of mongoexport utility?

While running the following command in the command line:

   mongoexport -h localhost:27000 -d dbName -c collName -q "{'time': { $gt: new Date('2014-01-28T12:00:00Z')}}" -o output.js

I'm getting the following error:

connected to: localhost:27000 assertion: 16619 code FailedToParse: FailedToParse: Expecting '}' or ',': offset:37

Reading Mongo Export query arg and JSONDocument docs haven't helped me to understand the expected format of query argument.

Running the same query in mongo shell succeeds.


Solution

  • If:

    >new Date ("2014-01-28T12:00:00Z").getTime()
    1390910400000
    

    You will have to construct your query as follows:

    -q "{sendToServerTime: {\$gt: {\$date : 1390910400000}}}"