Home > OS >  MongoDB Export with Query
MongoDB Export with Query

Time:05-04

In Mongodb, Mongoexport for collection is working on windows but when use --query getting the below error Failed: error parsing query as Extended JSON: invalid JSON input

--query="{'CreatedOnUtc' : { '$gt' : ISODate('2021-04-22T08:36:28.869Z')}}"

CodePudding user response:

Provides a query as a JSON document (enclosed in quotes) to return matching documents in the export.

You must enclose the query document in single quotes ('{ ... }') to ensure that it does not interact with your shell environment.

As per the documentation

Swap the single and double quotes in your query field.

For ex.

-q='{ "a": { "$gte": 3 }, "date": { "$lt": { "$date": "2016-01-01T00:00:00.000Z" } } }'

CodePudding user response:

I think the quotes are inverted, try the following

--query='{"CreatedOnUtc":{"$gt":ISODate("2021-04-22T08:36:28.869Z")}}'
  • Related