1

I really need help with the following problem with mongoexport :

  1. First of all the query is success with the following filter:

         db.payment_billers.find({
         createdDate : {
             $gte : ISODate("2022-04-01T00:00:00.000+07:00"),
             $lt : ISODate("2022-05-01T00:00:00.000+07:00")
          }
        })
    
  2. Then I tried to export the result to csv using this line:

     mongoexport --db=sigmob --collection=payment_billers
     --query='{createdDate : {$gte : ISODate("2022-04-01T00:00:00.000+07:00"),$lt : ISODate("2022-05-01T00:00:00.000+07:00")}}' --type=csv
     --fields=_id,accountSource.account.number,createdDate  --out=D:/download/220430/payment_billers.csv
    

Resulting :

2022-05-11T14:24:54.092+0700    error parsing command line options: error parsing positional arguments: provide only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
2022-05-11T14:24:54.093+0700    try 'mongoexport --help' for more information

I tried the script without using the query and works great. Really need help to correct the script, and thank you guys for the help and attention.

2
  • Try mongoexport -d sigmob -c payment_billers instead of mongoexport --db=sigmob --collection=payment_billers Commented May 11, 2022 at 8:07
  • Try this mongoexport -d=sigmob -c= payment_billers -q='{$and:[{ "createdDate": { "$gte": { "$date": "2022-04-01T00:00:00.000+07:00" } },{ "createdDate": { "$lt": { "$date": "2022-04-01T00:00:00.000+07:00" } }]}' --out=exportdir/myRecords.json Commented May 11, 2022 at 10:11

1 Answer 1

1

This error arises when there is some redundant text in the end of the command (mongoexport treats it as connection string, hence the message). It may happen because your shell doesn't interpret your command in the way you expect.

What type of shell do you use? It seems you may use Windows cmd, which doesn't support single quotes. You should rather use double quotes for --query argument and escape double quotes inside the query with """ (read more about this escaping rule here):

--query="{"""createdDate""" : {"""$gte""" : ISODate("""2022-04-01T00:00:00.000+07:00"""),"""$lt""" : ISODate("""2022-05-01T00:00:00.000+07:00""")}}"

Note that I use double quotes also for field name createdDate and operators $gte and $lt, which is mandatory in mongoexport (see docs).

In you are using Linux bash your command should work properly after just enclosing field name and operators in simple double quotes.

--query='{"createdDate" : {"$gte" : ISODate("2022-04-01T00:00:00.000+07:00"),"$lt" : ISODate("2022-05-01T00:00:00.000+07:00")}}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.