MongoExport Too many positional options - mongodb

Am trying to run a mongoexport using a remote connection by filtering on date ranges. A very simple query, however, I am running into positional errors issue. I;ve read through most of the posts regarding it, did the epoch conversion etc. But completely hit a block. Hopefully someone here can figure out what I am doing wrong.
Below is my command and the error message:
C:\ mongoexport --host 1.1.1.111:1111 --db IQ -u user -p password --collection CallLog --out calllog.json --query '{"Call.StartTime":{"$gte":new Date(1411066005000),"$lte": new Date(1406918805000)}}'
Error parsing command line: too many positional options
try 'mongoexport --help' for more information
We use the authenticationDatabase option when connecting and running queries from mongo. Tried the above using that as well. But same error.
What am I doing wrong here?
Thanks so much in advance.
Regards,
Simak

resolved this by interchanging the " and ' marks..Didn't realise that those made all the difference.
Thanks!

Related

How to restore a db in mongoDB

i tried to restore a db using mongorestore but i get this error:
2020-09-14T18:48:59.210+0200 error parsing command line options: error parsing positional arguments: provide only one polling interval in seconds and only one MongoDB connection string. Connection strings must begin with mongodb:// or mongodb+srv:// schemes
2020-09-14T18:48:59.258+0200 try 'mongorestore --help' for more information
I tried a lot of combinations, like this:
mongorestore -h localhost -d projectdb C:\Users\leo\Downloads\project\projectdbfiles
But without success.. i read the documentation and i tried to use --host:host and /host:host..
Im using windows
Below solution worked for me
Copy mongorestore.exe to C:\Users\leo\Downloads\project folder
open command prompt C:\Users\leo\Downloads\project\ location
mongoservice.exe projectdbfiles\
it should work.

MongoExport for field name where field name is not null

I have tried running the shell command:
mongoexport -d=local_db -c=ColName -q= '{ "FieldName":{"$ne":"null"}}' --out=NameofJson.json --jsonArray
But I return the error:
too many positional arguments: ['{ FieldName:{$ne:null}}']
What is the correct Syntax?
Get rid of the extra whitespace after -q:
-d=local_db -c=ColName -q='{ "FieldName":{"$ne":"null"}}' --out=NameofJson.json --jsonArray
If you are processing this in Linux please see Buzz Moschetti's answer. In windows the command was:
mongoexport -d=local_db -c=ColName -q="{ 'FieldName':{'$ne':null}}" --out=NameofJson.json --jsonArray

MongoDB replSet exception [duplicate]

The issue seems straight forward. I have a database (test) and a collection called (users) so I run the command:
mongoexport -d test -c users -o output.json
However I get the below error:
As per what I have figured out till now over the internet, this may have something to do with the file path but I am unsure as how to amend this as I never mess with PATH variable due to a bad experience...
You don't run mongoexport from the mongo shell, you have to run it from the OS shell (same as you run mongo)
mongoexport is not a Mongo shell command, it's an operating system command.
Just like you run mongo.exe to start the shell from OS prompt, you should run mongoexport the same way from OS prompt. Example:
c:\mongodb\bin>mongoexport --db ventfeed --collection users --out C:\temp\contacts.json
Thanks

Exporting collection from a Azure MongoDB

So I have a MongoDB in an Azure Cosmos DB service. It contains a collection of 1500 documents and I want to download this whole collection in a JSON format. I've tried several methods without success, namely
test_collection.find({})
Which gave me a cursor timeout. Using
{ timeout : false }
Did not help. Then I tried to use mongoexport:
mongoexport -h host_name --port 1234 -u user_name -p password
-d admin -c collection_name -o data.json --ssl
which gives me 0 exported records. The firewall IP access control is off and I can connect to the database through Mongo shell just fine. Trying to export other collections doesn't work either. Also, it has to be by ssl otherwise I get a "database not found" right away.
I've thought about using skip and limit but it doesn't seem to be a good idea with large (and expanding) collections? Could someone please give me some advise as to how I best achieve or overcome these obstacles to download my collection? It doesn't matter how, I just simply need to download the collection. Thank you.
You possibly have a few incorrect parameters, and a missing parameter:
Are you sure your database name is admin?
You need to specify --sslAllowInvalidCertificates
For host/port: this should look something like:
/h yourcosmosaccount.documents.azure.com:10255
If you take a look at the "quick start" tab in your Cosmos DB settings, you'll see the command line string for mongo (well, mongo.exe in the example). Just grab those parameters and use them for mongoexport.
I just ran this against a sample Cosmos DB (MongoDB API) database of mine, with no issue:
Here's the generic command-line equivalent:
mongoexport /h <host:port> /u <username> /p <password> /ssl /sslAllowInvalidCertificates /d <database> /c <collection> /o <outputfile>.json

What does "too many positional options" mean when doing a mongoexport?

mongoexport -h db.mysite.com -u myUser -p myPass -c myCollection
But the response I get is:
ERROR: too many positional options
What's that about?
I had this same problem. In my case, I was using mongoexport with the --query option, which expects a JSON document, such as:
mongoexport ... --query {field: 'value'} ...
I needed to surround the document with quotes:
mongoexport ... --query "{field: 'value'}" ...
I had the same problem. Found a group post somewhere which said to remove the space between the '-p' and the password, which worked for me.
Your sample command should be:
mongoexport -h db.mysite.com -u myUser -pmyPass -c myCollection
The same error I have encountered while importing a csv file.
But its just, the fact that the field list which you pass for that csv file import may have blank spaces.
Just clear the blank spaces in field list.
Its the parsing error.
I had the same issue with mongodump. After searching a bit, I found out that using the --out parameter to specify the output directory would solve this issue. The syntax for using the out parameter is
mongoexport --collection collection --out collection.json
Also in case your Mongodb instance isn't running, then you could use the --dbpath to specify the exact path to the files of your instance.
Source: http://docs.mongodb.org/manual/core/import-export/
I had the same issue with the mongoexport utility (using 2.0.2). My fix was to use the FULL parameter name (i.e. not -d, instead use --db).
Sometimes editor will screw it up (such as evernote). I fixed the issue by retyping the command in terminal.
I was also stuck in same situation and found what was causing it.
Make sure you are exporting in CSV format by adding parameter --type csv
Make sure there are no spaces in fields name,
Example: --fields _id, desc is wrong but --fields id,desc,price is good
This also works if you place the -c option first. For me, this order does work:
mongoexport -c collection -h ds111111.mlab.com:11111 -u user -p pass -d mydb
You can also leave the pass out and the server will ask you to enter the pass. This only works if the server supports SASL authentication (mlab does not for example).
for the (Error: Too many arguments)
Dont Use Space Between the Fields
try:
mongoexport --host localhost --db local --collection epfo_input --type=csv --out epfo_input.csv --fields cin,name,search_string,EstablishmentID,EstablishmentName,Address,officeName
Dont_Try:
mongoexport --host localhost --db local --collection epfo_input --type=csv --out epfo_input.csv --fields cin,name,search_string,Establishment ID,Establishment Name,Address,office Name
Had a similar issue
$too many positional arguments
$try 'mongorestore --help' for more information
Simply fix for me was to wrap the path location in quotes " "
This Failed:
mongorestore -h MY.mlab.com:MYPORT -d MYDBNAME -u ADMIN -p PASSWORD C:\Here\There\And\Back\Again
This Worked:
mongorestore -h MY.mlab.com:MYPORT -d MYDBNAME -u ADMIN -p PASSWORD "C:\Here\There\And\Back\Again"
I had the same issue with starting mongod. I used the following command:
./mongod --port 27001 --replSet abc -- dbpath /Users/seanfoley/Downloads/mongodb-osx-x86_64-3.4.3/bin/1 --logpath /Users/seanfoley/Downloads/mongodb-osx-x86_64-3.4.3/log.1 --logappend --oplogSize 5 --smallfiles --fork
The following error message appeared:
Error parsing command line: too many positional options have been specified on the command line
What fixed this issue was removing the single space between the '--' and 'dbpath'
I had the same issue while using the "mongod --dbpath" command. What I was doing looked somewhat like this:
mongod --dbpath c:/Users/HP/Desktop/Mongo_Data
where as the command syntax was supposed to be:
mongod --dbpath=c:/Users/HP/Desktop/Mongo_Data
This worked for me. Apart from this one may take a note of the command function and syntaxes using the mongod --help command.
In my case, I had to write the port separately from the server connection. This worked for me:
mongoexport --host=HOST --port=PORT --db=DB --collection=COLLECTION
--out=OUTPUT.json -u USER -p PASS
Create a json file in the same folder where you have your mongod.exe.
eg: coll.json
and open a command prompt in this folder.
type this below in CMD.
mongoexport --db databasename --collection collectionname --out
coll.json
and you will see like a progress bar very cool exporting all data.