Query syntax for mongoexport

Hi,

I’m trying to pass in a query to mongoexport like this:
mongoexport --uri=“mongodb+srv://dev:removed@server/feedback” --collection=entries --query=’{ “date”: { “$lt”: { “$date”: “2020-02-28T00:00:00.000Z” } } }’ --out=dispatcher.json

But I am getting an error:
2020-07-28T12:43:39.366+0100 query ‘[123 32 100 97 116 101 58 32 123 32 36 108 116 58 32 123 32 36 100 97 116 101 58 32 50 48 50 48 45 48 50 45 50 56 84 48 48 58 48 48 58 48 48 46 48 48 48 90 32 125 32 125 32 125]’ is not valid JSON: invalid character ‘-’ after object key:value pair

I also tried with IsoDate:
mongoexport --uri=“mongodb+srv://dev:removed@server/feedback” --collection=entries --query=’{ “date”: { “$lt”: IsoDate(“2020-02-28T00:00:00.000Z”) } }’ --out=dispatcher.json
2020-07-28T13:39:37.818+0100 query ‘[123 32 100 97 116 101 58 32 123 32 36 108 116 58 32 73 115 111 68 97 116 101 40 50 48 50 48 45 48 50 45 50 56 84 48 48 58 48 48 58 48 48 46 48 48 48 90 41 32 125 32 125]’ is not valid JSON: invalid character ‘s’ in literal Infinity or ISO (expecting ‘n’ or ‘S’)

What am I doing wrong?

-Paul

Hello @Alexandru_Paul_Csiki, welcome to the forum.

There was a similar question couple of months back, on this forum. Here is the link to it. In that case, it was the query used with mongodump , but the syntax for the query option is same (I think). Please check the post and tell us if it helped.

Mongodump –query not able to filter using timestamp

Also, include a sample document showing the field(s) used in the query and the operating system you are working with.

1 Like

Thank you, that worked. Here’s the CLI I’ve used:
λ mongoexport --host server --ssl --username dev --password omitted --authenticationDatabase admin --db feedback --collection entries --type json --out dispatcher.json --query=’{“date”: {"$lt": {"$date": “2020-02-28T00:00:00.000Z”}}}’

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.