Mongodb export --query results in error "...provide only one MongoDB connection string"

Trying to figure out why the addition of the query causes the parse to fail.

The original mongoexport command works fine:

mongoexport --uri=“mongodb+srv://username:password@abcd-uat-pl-0.i48a5.mongodb.net/DBTEST” --collection=“COLLTEST” --fields=“IssuingBank,amount,orderRef,paymentId,payMethod,receivedDate,status,transRef” --type=csv --out=“C:\MIB\Technology\PowerBI\mongodb\test1.csv”

2025-07-15T15:13:18.858+0800 connected to: mongodb+srv://[REDACTED]@abcd-uat-pl-0.i48a5.mongodb.net/DBTEST
2025-07-15T15:13:19.117+0800 exported 3354 records

When the --query option is added

mongoexport --uri=“mongodb+srv://username:password@abcd-uat-pl-0.i48a5.mongodb.net/DBTEST” --collection=“COLLTEST” --fields=“IssuingBank,amount,orderRef,paymentId,payMethod,receivedDate,status,transRef” –query=‘{“header.signedDate”: {“$gt”: {“$date”: “2025-06-19T00:00:00.000Z”}}}’ --type=csv --out=“C:\MIB\Technology\PowerBI\mongodb\test1.csv”

2025-07-15T15:57:26.733+0800 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
2025-07-15T15:57:26.783+0800 try ‘mongoexport --help’ for more information

Check your syntax again.It should be double hypen before “-c”
Also check this link

Error parsing command line options: error parsing positional arguments:

Is this the right way to specify a query? I got the same error changing to double hyphen

--query='{"header.signedDate": {"$gt": {"$date": "2025-06-19T00:00:00.000Z"}}}'

Replace single quotes with double quotes at begin and end of query and escape all double quotes with back slash in inner query
You can refer to this link
Mongodump –query not able to filter using timestamp

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.