Request Mongoexport -q ISODate

I am trying to run this:

mongoexport.exe -h *MYHOST* -p *MYPORT* -q "{'time':{'$gte': ISODate('2014-12-21 12:57:00.506Z'),'$lt': ISODate('2014-12-21 12:59:00.506Z')}}" 

Or this (gte and lt without - '):

 mongoexport.exe -h *MYHOST* -p *MYPORT* -q {'time':{$gte: ISODate('2014-12-21 12:57:00.506Z'),$lt: ISODate('2014-12-21 12:59:00.506Z')}} 

The request works fine on Robomongo, but with mongoexport it throws: "too many positional arguments"

I know that I can run the following instead. But I do not want to use a date converter every time I need to execute a query.

 mongoexport.exe -h *MYHOST* -p *MYPORT* -q "{'time':{$gte: new Date(14191 66620506),$lt: new Date(1419166740506)}}" 
+8
source share
4 answers

Mongoexport requests require the use of extended JSON in MongoDB strict mode. You can learn more about this flavor of extended JSON in the MongoDB tutorial on extended JSON . In your particular case, the correct way to write the first request in the mongoexport command is

 mongoexport.exe -h *MYHOST* -p *MYPORT* -q "{ 'time' : { '$gte' : { '$date' : '2014-12-21 12:57:00.506Z' },'$lt' : { '$date' : '2014-12-21 12:59:00.506Z' } } }" 
+12
source

I used @wdberkeley's answer as a starting point, but this date string did not work for me. I had to use a "T" to separate the date and time:

 mongoexport --username user --password pass --host host --db dbName --collection coll --type=csv --query '{"_created_at": { "$gte" : { "$date" : "2017-12-21T12:57:00.506Z" } }}' 
+6
source

I had to use a different syntax in windows.

mongoexport --host 192.168.1.5 --db dbname --collection files --query "{" ModifyDate ": {" $ lte ": {" $ date ": '2019-02-17T00: 00: 00.000Z'}} } "

The difference is in single quotes around the date.

0
source

I had the same problem with mongo 2.4, you need to use $ date with a “64-bit signed integer for milliseconds” ( https://docs.mongodb.com/v2.4/reference/mongodb-extended-json/ ) a case of you:

 mongoexport.exe -h *MYHOST* -p *MYPORT* -q "{'time':{'$gte':{"$date": 1419166620506},'$lt': {"$date": 1419166740506}}" 
0
source

Source: https://habr.com/ru/post/980004/


All Articles