Mongodump invalid json

Hello,

I’m having this error running mongodump:

mongodb@shards:~$ mongodump --port 27005 --db phoenix --collection audit_log --query ‘{ “_id”: { “$gt”: ObjectId(“5c2bcb014cf5143349ee0fd7”) }}’ --out /mnt/backup/mongodump/date +"%m-%d-%y" --verbose
2022-05-27T12:34:16.590+0200 will listen for SIGTERM, SIGINT, and SIGKILL
2022-05-27T12:34:16.643+0200 Failed: error parsing query as Extended JSON: error decoding key _id: invalid JSON input. Position: 18. Character: O

mongodb@shards:~$ mongodump --port 27005 --db phoenix --collection audit_log --query ‘{ “_id”: { “$gt”: {“ObjectId”(“626ecf14679c0b146a8c8184”) }}}’ --out /mnt/backup/mongodump/date +"%m-%d-%y" --verbose
2022-05-27T14:13:07.212+0200 will listen for SIGTERM, SIGINT, and SIGKILL
2022-05-27T14:13:07.216+0200 Failed: error parsing query as Extended JSON: error decoding key _id.$gt: invalid JSON input: missing colon after key “ObjectId”

My syntax is not correct?

Thanks in advance.

Regards

Hello @Agusti_Luesma_Termens, Welcome to the MongoDB community forum,

As per the documentation of --query, The query must be in Extended JSON v2 format (either relaxed or canonical/strict mode).

And see what format mongodump command supports,

So you have to use the canonical format of the object id instead of ObjectId function,

{ "_id": { "$gt": { "$oid": "5c2bcb014cf5143349ee0fd7" } } }
3 Likes