Mongodump --query not able to filter using timestamp

mongodump --host=“rs0/localhost:27017,localhost:27018,localhost:27019” --readPreference=secondary -d local -c oplog.rs --query="{“ts”:{"$gte":"$Timestamp(0000000000,50)"}}" -vvv -o /home/anupama/backupec2

I am getting output

writing local.oplog.rs to
2020-03-29T08:37:08.134+0530 not counting query on local.oplog.rs
2020-03-29T08:37:08.328+0530 done dumping local.oplog.rs (0 documents)
2020-03-29T08:37:08.328+0530 ending dump routine with id=0, no more work to do
2020-03-29T08:37:08.328+0530 dump phase III: the oplog
2020-03-29T08:37:08.328+0530 finishing dump

But when try to dump without using query it dumps the file

I think you have to escape $ sign
or use single quote for json query

1 Like

mongodump --host=“rs0/localhost:27017,localhost:27018,localhost:27019” --readPreference=secondary -d local -c oplog.rs --query="{“ts”:{"$gte":"$Timestamp(0000000000,50)"}}" -vvv -o /home/anupama/backupec2

The query is to be formatted according to the mongodump’s Extended JSON v2. This will work with Windows system (e.g.,):

"{ \"ts\":{ \"$gte\": { \"$timestamp\": { \"t\": 1565545664, \"i\": 1 } } } }"

The backslash (\) character is to escape the double-quote (") within the outer quotes.

1 Like

Thanks for the update but when i tried it on startup_log give below

done dumping local.startup_log (0 documents)
2020-03-30T10:00:32.595+0530 finishing dump

Tried lt,gt etc Gives same result
In your case did it dump rows?

Please post couple of sample input documents.

Will this help?

> db.getCollection('startup_log').find().limit(2).pretty()
{
        "_id" : "DESKTOP-RIP97MG-1547099484533",
        "hostname" : "DESKTOP-RIP97MG",
        "startTime" : ISODate("2019-01-10T05:51:24Z"),
        "startTimeLocal" : "Thu Jan 10 11:21:24.533",
        "cmdLine" : {
                "config" : "C:\\Program Files\\MongoDB\\Server\\4.0\\bin\\mongod.cfg",
                "net" : {
                        "bindIp" : "127.0.0.1",
                        "port" : 27017
                },
                "service" : true,
                "storage" : {
                        "dbPath" : "C:\\Program Files\\MongoDB\\Server\\4.0\\data",
                        "journal" : {
                                "enabled" : true
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "C:\\Program Files\\MongoDB\\Server\\4.0\\log\\mongod.log"
                }
        },
        "pid" : NumberLong(13372),
        "buildinfo" : {
                "version" : "4.0.5",
                "gitVersion" : "3739429dd92b92d1b0ab120911a23d50bf03c412",
                "targetMinOS" : "Windows 7/Windows Server 2008 R2",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        4,
                        0,
                        5,
                        0
                ],
                "openssl" : {
                        "running" : "Windows SChannel"
                },
                "buildEnvironment" : {
                        "distmod" : "2008plus-ssl",
                        "distarch" : "x86_64",
                        "cc" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24223 for x64",
                        "ccflags" : "/nologo /EHsc /W3 /wd4355 /wd4800 /wd4267 /wd4244 /wd4290 /wd4068 /wd4351 /wd4373 /we4013 /we4099 /we4930 /WX /errorReport:none /MD /O2 /Oy- /bigobj /utf-8 /Zc:rvalueCast /Zc:strictStrings /volatile:iso /Gw /Gy /Zc:inline",
                        "cxx" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24223 for x64",
                        "cxxflags" : "/TP",
                        "linkflags" : "/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF",
                        "target_arch" : "x86_64",
                        "target_os" : "windows"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}
{
        "_id" : "DESKTOP-RIP97MG-1547362502494",
        "hostname" : "DESKTOP-RIP97MG",
        "startTime" : ISODate("2019-01-13T06:55:02Z"),
        "startTimeLocal" : "Sun Jan 13 12:25:02.494",
        "cmdLine" : {
                "config" : "C:\\Program Files\\MongoDB\\Server\\4.0\\bin\\mongod.cfg",
                "net" : {
                        "bindIp" : "127.0.0.1",
                        "port" : 27017
                },
                "service" : true,
                "storage" : {
                        "dbPath" : "C:\\Program Files\\MongoDB\\Server\\4.0\\data",
                        "journal" : {
                                "enabled" : true
                        }
                },
                "systemLog" : {
                        "destination" : "file",
                        "logAppend" : true,
                        "path" : "C:\\Program Files\\MongoDB\\Server\\4.0\\log\\mongod.log"
                }
        },
        "pid" : NumberLong(3796),
        "buildinfo" : {
                "version" : "4.0.5",
                "gitVersion" : "3739429dd92b92d1b0ab120911a23d50bf03c412",
                "targetMinOS" : "Windows 7/Windows Server 2008 R2",
                "modules" : [ ],
                "allocator" : "tcmalloc",
                "javascriptEngine" : "mozjs",
                "sysInfo" : "deprecated",
                "versionArray" : [
                        4,
                        0,
                        5,
                        0
                ],
                "openssl" : {
                        "running" : "Windows SChannel"
                },
                "buildEnvironment" : {
                        "distmod" : "2008plus-ssl",
                        "distarch" : "x86_64",
                        "cc" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24223 for x64",
                        "ccflags" : "/nologo /EHsc /W3 /wd4355 /wd4800 /wd4267 /wd4244 /wd4290 /wd4068 /wd4351 /wd4373 /we4013 /we4099 /we4930 /WX /errorReport:none /MD /O2 /Oy- /bigobj /utf-8 /Zc:rvalueCast /Zc:strictStrings /volatile:iso /Gw /Gy /Zc:inline",
                        "cxx" : "cl: Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24223 for x64",
                        "cxxflags" : "/TP",
                        "linkflags" : "/nologo /DEBUG /INCREMENTAL:NO /LARGEADDRESSAWARE /OPT:REF",
                        "target_arch" : "x86_64",
                        "target_os" : "windows"
                },
                "bits" : 64,
                "debug" : false,
                "maxBsonObjectSize" : 16777216,
                "storageEngines" : [
                        "devnull",
                        "ephemeralForTest",
                        "mmapv1",
                        "wiredTiger"
                ]
        }
}
>

–query="{“ts”:{"$gte":"$Timestamp(0000000000,50)"}}

So, where is the field ts in the documents? Are you querying on some other field?

Please check the documents and the field you are querying upon - the field name must be same.

I tried with startTime but still same result

“startTime” : ISODate(“2019-01-13T06:55:02Z”) is not is timestamp data type; it is Date data type.

For your case, use this format with the correct date string:

--query "{ \"startTime\":{ \"$gte\": { \"$date\": \"2020-02-14T04:07:34Z\" } } }"

1 Like

Thank you very much

It worked with date format

2020-03-30T11:55:05.934+0530 done dumping local.startup_log (4 documents)
2020-03-30T11:55:05.934+0530 dump phase III: the oplog
2020-03-30T11:55:05.936+0530 finishing dump

worked thanks for replying