Invalid json input error while executing mongodump in MongoDB 4.2

2,330 views
Skip to first unread message

Akshaya Srinivasan

unread,
Sep 19, 2019, 11:15:56 AM9/19/19
to mongodb-user
Hi,

I have a mongoDB 4.2 replica set in my centos 7 machine. mongodump is failing with below error while parsing. Please can someone provide a solution to it.

[root@mongolinux Log_Files]# mongodump --port 27088 --host mongolinux --db local --collection oplog.rs --out "/Results/2/2843"  --query "{ts:{\$gt:Timestamp(1568904578,1)}}" -u mo_user -p'test!12' --authenticationDatabase 'admin'
2019-09-19T20:41:41.823+0530    Failed: error parsing query as Extended JSON: invalid JSON input



[root@mongolinux Log_Files]# mongo --version
MongoDB shell version v4.2.0
git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

Kevin Adistambha

unread,
Sep 23, 2019, 1:14:41 AM9/23/19
to mongodb-user

Hi,

The JSON format is quite particular about quotes. Each field name must be surrounded by double quotes. Single quotes or no quotes are not actually valid JSON.

Also, Timestamp(...) is not valid JSON either, since it is a function call.

In your example, the --query should be following the extended JSON format specifically the timestamp format, so it should be like:

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

Note the double quotes surrounding the field names and the single quote surrounding the whole query.

Best regards,
Kevin

Akshaya Srinivasan

unread,
Sep 27, 2019, 3:16:38 AM9/27/19
to mongodb-user
Thanks Kevin.

It worked.

Thanks,
Akshaya Srinivasan

Akshaya Srinivasan

unread,
Oct 3, 2019, 6:13:17 AM10/3/19
to mongodb-user
Hi Kevin,

But this works on Linux using mongoDB 4.0 and 4.2. But it doesn't work on mongoDB 4.0 on windows. What format do we use on windows?


C:\Program Files\MongoDB\Server\4.0\bin>"C:\Program Files\MongoDB\Server\4.0\bin\mongodump" --port 27020 --host mysqlwin --db local --collection oplog.rs --out"C:\tmp"  --query '{"ts": {"$gt": {"$timestamp": {"t": 1569926648, "i": 1}}}}'
2019-10-03T15:33:39.886+0530    positional arguments not allowed: [{$gt: {$timestamp: {t: 1569926648, i: 1}}}}']
2019-10-03T15:33:44.212+0530    try 'mongodump --help' for more information


Thanks,
Akshaya Srinviasan

On Monday, September 23, 2019 at 10:44:41 AM UTC+5:30, Kevin Adistambha wrote:

hari dba

unread,
Oct 3, 2019, 9:43:05 AM10/3/19
to mongod...@googlegroups.com
do not use 2 times bin path one time enough like below sample
.
C:\Program Files\MongoDB\Server\4.0\bin>mongodump" --port 27020 --host mysqlwin --db local --collection oplog.rs  --query '{"ts": {"$gt": {"$timestamp": {"t": 1569926648, "i": 1}}}}' --out "C:\tmp" 

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/75142b05-1637-478b-a976-03e48535b9ec%40googlegroups.com.

Akshaya Srinivasan

unread,
Feb 17, 2020, 3:43:56 AM2/17/20
to mongodb-user

Hi Hari,

It doesn't work still

C:\Users\Administrator\Downloads\mongodb-win32-x86_64-2012plus-4.2.2\mongodb-win32-x86_64-2012plus-4.2.2\bin>mongodump --port 27017 --db local --collection oplog.rs  --query '{"ts": {"$gt": {"$timestamp": {"t": 1569926648, "i": 1}}}}' --out "C:\tmp"
2020-02-17T14:10:50.802+0530    positional arguments not allowed: [{$gt: {$timestamp: {t: 1569926648, i: 1}}}}']
2020-02-17T14:10:50.806+0530    try 'mongodump --help' for more information


Thanks,
Akshaya Srinviasan
To unsubscribe from this group and stop receiving emails from it, send an email to mongod...@googlegroups.com.

hari dba

unread,
Feb 24, 2020, 12:44:54 PM2/24/20
to mongod...@googlegroups.com
Hi Akshsya,
Thank for checked and informed me.

Here, I did checked mongodb 4.2.2 version mongodump by using query option below mentioned sample MongoDB Command  
you just change your query like this: 

D:\4.2.2\bin>mongodump --port 27082 --db pms --collection purchase1 -q "{\"x\":{\"$gt\":10}}" --out D:\backup_export\admin\ 

Once you tested according  to your mongoDB let me know either above command worked or not from your side.
Reply all
Reply to author
Forward
0 new messages