mongodb-error validating settings: only one positional argument is allowed

26.1k views Asked by At

I just moved to a new laptop which had mongo 3.0.0 I believe. On the new laptop I have mongo 3.0.4. and trying the script that was working on the old laptop is giving me errors. This line is giving me the error.

mongoimport --host localhost \
            -db roudy123_q \
            -collection LebaneseAmericanUniversity\(Lebanon\).json \
            --file LebaneseAmericanUniversity\(Lebanon\).json \
            --jsonArray

error validating settings: only one positional argument is allowed.

I googled the error and the only relevant result was the source code of mongoimport. So I guess it has something to do with the new version.

7

There are 7 answers

3
Sylvain Leroux On BEST ANSWER

Just a wild guess...

... but the various long options should be specified using --, not -:

mongoimport --host localhost \
            --db roudy123_q \
            --collection LebaneseAmericanUniversity\(Lebanon\).json \
            --file LebaneseAmericanUniversity\(Lebanon\).json \
            --jsonArray

Maybe this particular version of mongoimport is more punctilious about that, and will treat -db ... -collection ... as positional arguments rather than keyword arguments ?

0
ranjeet rai On

If you are getting mongodb-error validating settings: only one positional argument is allowed.

  1. Just put --file path in " ".

2.use / instead of \ in --file path.

  1. Also, put --host in " ".

For example:
Suppose you are trying to import data from your local machine to server (MongoDB Atlas or your MongoDB server or locally) in your collection then follow this:

mongoimport --host "cluster0-shard-00-01-ceax1.mongodb.net:27017" --db <dbname> --type json --file "C:/Users/ranjeet/Downloads/MongoDb project/ranjeet.json" --authenticationDatabase admin --ssl --username <Username> --password <Password> --collection <CollectionName>
0
Ankit Marothi On

If you get this error while inserting fields with --fields, the probable reason might be you are using spaces to do that.

Both -f and --fields should work in those cases Using Mongo Version 3.0.6

mongoimport --db logs --collection action_logs --type tsv -f updated_at ,transaction_time ,origin  --file parsed.tsv
mongoimport --db logs --collection action_logs --type tsv -f updated_at,transaction_time,origin  --file parsed.tsv
0
kapil pandey On

None of the above mentioned answers solved my problem but they indeed helped me in figuring out what I was doing wrong.(I am using windows)

1)using -d instead of --d (shorthand only require one - not two --)

2)using "" for absolute file path.

3)Changing \ to / in file path location.

For example my files location in windows is: C:\kp github\other projects\projectXyz\myFile.csv

So for me the command that worked was:

mongoimport -d users -c contacts --type=csv --headerline --file="C:/kp github/other projects/projectXyz/myFile.csv" or

mongoimport -d users -c contacts --type csv --headerline --file "C:/kp github/other projects/projectXyz/myFile.csv"

where users is my db name and contacts is my collection name

0
Mohan On

I think giving a white spaces in the file name of directory will also contribute to this error.

0
Ari On

The below is the correct example of command when your database have user name and password created

mongoimport --host 127.0.0.1
--port 27000
--username XXXXX
--password PPPPP
--authenticationDatabase admin
--db applicationData
--collection products
--file products.json

Please make sure you do not have any extra spaces after
and before -- as well.

0
rakshith91 On

This error can also occur if white spaces are given without a "\" in the path to the file . Ex: This wont work: Error

But this would work :

works fine