mongoimport : 'error validating settings: only one positional argument is allowed'
Asked Answered
B

6

7

Ok so I am trying.... to Importing a dummy JSON file into MongoDB and getting this error, a Google search yields no definitive explanation, and though this topic is already on here, that's more a syntax related error.

I think my syntax is ok, however if it is not please point it out and let me know. Also I think the other issue is my path [format correct] ? or is it something entirely different I am missing.

I don't understand the error and thus can't find a suitable "plain English" explanation anywhere to figure it out myself, so if you have a link please drop it in for me, it will be appreciated....

The error:

$ mongoimport --jsonArray --collection bank_data /Macintosh HD/Users/Tinus/Downloads/bank_data.json/bank_data.json
2016-09-20T13:23:56.592+1200    error validating settings: only one positional argument is allowed

-: Running OSX -: Mongod started -: Using /data/db path and connected to test "All good" -: running mongoimport from separate shell


$ mongo --version MongoDB shell version: 3.2.8

$ mongoimport --jsonArray --collection some_data --file /path/path/data.json
$ mongoimport --jsonArray --collection some_data /path/path/data.json

A) Also when adding --file i get: incompatible options: --file and positional argument(s)

Broadfaced answered 20/9, 2016 at 1:47 Comment(0)
G
9

Try it like that by quoting your path

$ mongoimport --jsonArray --collection bank_data '/Macintosh HD/Users/Tinus/Downloads/bank_data.json/bank_data.json'  

The error

error validating settings: only one positional argument is allowed

comes from the fact that your path contains a space which results in splitting it into two separate arguments (if not guarded by surrounding quotes)


BTW: Are your sure your path ends with '...bank_data.json/bank_data.json' and not just one 'bank_data.json'?

Grownup answered 20/9, 2016 at 4:8 Comment(2)
Thanks so much mate! Will give it a go and let you know. IBroadfaced
Mine was a different import scenario. I was using data types and trying to specify date format like date_ms(yyyy-MM-dd H:mm:ss) [as shown in mongoimport docs]. got this same error and when quoted such as date_ms('yyyy-MM-dd H:mm:ss'), the error's gone and import worked!Sigismond
B
3

~Fix~

A) I changed the path to reed direct from a new folder on root B) For any other’s having the same issue on mac osx —leave out the base root in your path , in my example above it was [ Macintosh HD] the import works without specifying it. thus it was changed to ..

        $ mongoimport --jsonArray --collection bank_data '/Users/Tinus/Downloads/bank_data.json/bank_data.json'

C) Yes the quotes are essential and was also added… D) Remember not to run it inside the mongo shell.

thumbs Up again to DAXaholic

Broadfaced answered 21/9, 2016 at 2:16 Comment(0)
C
1

I also had the same error and the reason was my mistake of specifying options. Instead of --collection or -c, I had -collection. Below is what worked for me.

mongoimport --db ShardTestDB --collection Test --host : --jsonArray --file "<path_to_json>/Substations_new.json"

Make sure that the file is included inside quotes.

Civilization answered 6/7, 2020 at 5:49 Comment(0)
C
0

even i faced same issue while importing tsv file to db including --headerline to the command line solved the issue.please find entire import command used to successfully import tsv file

mongoimport --host Cluster0-shard-0/cluster0-shard-00-00-qvmvm.mongodb.net:27017,cluster0-shard-00-01-qvmvm.mongodb.net:27017,cluster0-shard-00-02-qvmvm.mongodb.net:27017 --ssl --username learning --password --authenticationDatabase admin --db node_deploy --collection node_deploy --type tsv --file games.tsv --headerline [Note] above command is to import a database in tsv format to mongodb hosted in AWS using mongodb.com

Crites answered 26/4, 2019 at 10:16 Comment(0)
I
0

Above solutions did not work for me on Windows 10. I figured out solution as follows:

mongoimport --jsonArray --db=db_name --collection=collection_name --file=file_name.json

Which resulted in:

2019-12-29T02:26:50.041-0700    connected to: mongodb://localhost/
2019-12-29T02:26:50.088-0700    2411 document(s) imported successfully. 0 document(s) failed to import.
Intervalometer answered 29/12, 2019 at 9:34 Comment(0)
L
0

This worked for me:

mongoimport --host 172.18.60.1 --port 50000 --db MYDB --collection BUSINESS_FILE --file "/opt/data/JSON/BUSINESS_FILE.json"

P.S. My port is not default port of MongoDB so make sure you put your mongos port there instead of 50000 which is mine.

Libation answered 27/4, 2020 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.