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

7

15

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.

Brazier answered 20/6, 2015 at 11:45 Comment(0)
P
31

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 ?

Psalterium answered 20/6, 2015 at 13:21 Comment(3)
I can't believe I wasted several hours on that ugh. Hopefully it will save someone else's time. Thanks.Brazier
I got my issue fixed with this. But this syntax used to work for me earlier(till this year start). My batch file broke sometime back. ThanksWastepaper
It saved me hours :)Hyperaemia
J
6

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

Janaye answered 23/4, 2016 at 16:44 Comment(0)
E
1

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>
Eruct answered 16/7, 2020 at 13:50 Comment(0)
A
0

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
Admass answered 26/11, 2015 at 11:58 Comment(0)
S
0

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

Surfboard answered 15/3, 2016 at 23:1 Comment(0)
H
0

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

Heterosexuality answered 29/5, 2020 at 17:25 Comment(0)
M
0

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.

Maddalena answered 6/7, 2022 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.