Mongodump command is failing in MongoDB4.4 with JSON error

Hi,

I was try mongodump command on windows, with MongoDB 4.4 server, but it fails withe below error.
Same command goes fine on ubuntu.
Is any change in timestamp format required?

C:\MMSAutomation\versions\mongodb-windows-x86_64-4.4.1\bin>mongodump --port 27999 --host apple --db local --collection oplog.rs --out "C:\Program Files\mydump"  --query "{"ts":{"$gt":{"$timestamp":{"t":1600853643,"i":1}}}}"
2020-09-23T15:48:43.465+0530    Failed: error parsing query as Extended JSON: invalid JSON input

Thanks,
Akshaya Srinivasan

You have quoting issues in your query, I highly doubt this would work on the ubuntu command line as is either.

Make your outside quotes single ' .

--query '{"ts":{"$gt":{"$timestamp":{"t":1600853643,"i":1}}}}'

Thanks @chris

On windows:

C:\MMSAutomation\versions\mongodb-windows-x86_64-4.4.1\bin>“C:\MMSAutomation\versions\mongodb-windows-x86_64-4.4.1\bin\mongodump” --port 27999 --host apple --db local --collection oplog.rs --out “C:\Program Files\2284” --query ‘{“ts”:{“$gt”:{“$timestamp”:{“t”:1600853643,“i”:1}}}}’

2020-09-23T16:36:53.714+0530 Failed: error parsing query as Extended JSON: invalid JSON input

On ubuntu20:

mongodump --port 27017 --host aksubuntu20 --db local --collection oplog.rs --out “/1199” --query ‘{“ts”:{“$gt”:{“$timestamp”: {“t”: 1600851861, “i”: 1}}}}’

2020-09-23T16:35:55.803+0530 writing local.oplog.rs to /1199/local/oplog.rs.bson
2020-09-23T16:35:55.809+0530 done dumping local.oplog.rs (1700 documents)

Still running into some quoting issue on the windows command line. I don’t have windows to hand to assist further.

You can put your query in a file and use the the --queryFile= option if you want to avoid this and get your dump running.

Thanks @chris

But using a file is not preferable.

The query has to be formatted on Windows
Please check this link

Mongodump –query not able to filter using timestamp

1 Like

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