I have a collection sampleColl.
MongoDB Enterprise > db.sampleColl.find().limit(3);
{ "_id" : ObjectId("64f01e4f58e834c50cdf63c1"), "field" : "2ed2892b" }
{ "_id" : ObjectId("64f01e4f58e834c50cdf63c2"), "field" : "b48ec1ad" }
{ "_id" : ObjectId("64f01e4f58e834c50cdf63c3"), "field" : "1d02b0c2" }
When I try to create bson file for the entire collection it works fine.
D:\mongodb-database-tools-100.8.0\bin>mongodump --uri="mongodb://127.0.0.1:27017/test" --collection=sampleColl --out=dump --gzip --verbose
2023-08-31T10:40:06.606+0530 dumping up to 1 collections in parallel
2023-08-31T10:40:06.613+0530 writing test.sampleColl to dump\test\sampleColl.bson.gz
2023-08-31T10:40:06.679+0530 done dumping test.sampleColl (10000 documents)
Now, if I try to limit the documents using --query argument, I run into an error.
D:\mongodb-database-tools-100.8.0\bin>mongodump --uri="mongodb://127.0.0.1:27017/test" --collection=sampleColl --query='{"field": {"$gt": "5"}}' --out=dump --gzip --verbose
2023-08-31T10:42:05.872+0530 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
2023-08-31T10:42:05.873+0530 try 'mongodump --help' for more information
After several trial and errors,
In Windows Command Prompt, escape the
"with\and enclose the query in"(double quotes).In Windows PowerShell (PSVersion 5.1.22000.2003), escape the
"with\and enclose the query in'(single quote).