0

mongodump failing with invalid json input

mongod --version
db version v3.4.1
git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
OpenSSL version: OpenSSL 1.0.2n  7 Dec 2017
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1404
    distarch: x86_64
    target_arch: x86_64

/usr/bin/mongodump -u backup -p backup12345 --host=XX.XX.XX.XX --port XXXX --out=/tmp -d local -c oplog.rs --gzip --authenticationDatabase admin --query "{'ts': { $gt: Timestamp(1619548593, 1) } }" --ssl --sslAllowInvalidCertificates

2021-04-28T01:21:37.694-0700 Failed: error parsing query as Extended JSON: invalid JSON input

anyone can figure what's the issue here ?

I understand that I'm using 3.4.1 which is older but still it is working on the other server and with same version. The same query runs perfectly alright on a different cluster node.

Also tried using the latest version of mongodump still the same error.

mongodb-database-tools-ubuntu1804-x86_64-100.3.1.tgz


I passed the same --query parameter as below in my command and I'm getting corresponding error

--query '{ "ts": { "$gt": Timestamp(1111111, 1) }}'

2021-04-28T11:10:01.328-0700 Failed: error parsing query as Extended JSON: error decoding key ts: invalid JSON input. Position: 17. Character: T

--query '{ "ts": { "$gt": ISODate("2021-04-05T08:00:00.000Z") }}'

2021-04-28T11:10:35.627-0700 Failed: error parsing query as Extended JSON: error decoding key ts: invalid JSON input. Position: 17. Character: I

--query "{ 'ts': { \$gt:  ISODate(\"2021-04-05T08:00:00.000Z\") }}"

2021-04-28T11:11:20.797-0700 Failed: error parsing query as Extended JSON: invalid JSON input

Paul White
  • 94,921
  • 30
  • 437
  • 687
unknown
  • 104
  • 2
  • 11

1 Answers1

1

Try adjusting the input:

/usr/bin/mongodump -u backup -p backup12345  --host=XX.XX.XX.XX --port XXXX --out=/tmp -d local -c oplog.rs --gzip --authenticationDatabase admin \
--query '{"ts": { "$gt": Timestamp(1619548593, 1) } }'
--ssl --sslAllowInvalidCertificates

I tried multiple versions and they worked fine with me:

  • --query '{ "ts": { "$gt": Timestamp(1111111, 1) }}'
  • --query '{ "ts": { "$gt": ISODate("2021-04-05T08:00:00.000Z") }}'
  • --query "{ 'ts': { \$gt: ISODate(\"2021-04-05T08:00:00.000Z\") }}"

In older mongo versions you need to use the "extended json":

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

this is completetly valid json and should work with the old client as well.

also see mongodump command with timestamp query

Paul White
  • 94,921
  • 30
  • 437
  • 687
Niko
  • 113
  • 3