1

I am trying to import json using bash script but it does not seem to be working properly

The error that I am getting is: error validating settings: incompatible options: --file and positional argument(s)

Here is the script that I am trying to run

importserver="localhost:27017"
username="username"
password="password"
importdb="Hotel"
collections=("Customers")

echo "Begin To Import"

for c in ${collections[@]}
do
    echo "importing $c .."
     mongoimport $importserver --db $importdb --collection $c --file "$c.json"
done

echo "Done."

I have tried changing params and everything. None seems to work

1 Answer 1

1

You are very close. Need to add the --host parameter...

importserver="localhost:27017"                                                                                                             
username="username"
password="password"
importdb="Hotel"
collections=("Customers")

echo "Begin To Import"

for c in ${collections[@]}
do
    echo "importing $c .."
     mongoimport --host $importserver --db $importdb --collection $c --file "$c.json"
done

echo "Done."

The error message error validating settings: incompatible options: --file and positional argument(s) is saying there is a parameter - the host name parameter - that has no tag and therefore must be identifiable by its position, but positional arguments usually go at the end. Rather than use a positional argument, if you add the --host it will be a named argument instead. I think there are some gotchas about which parameters are allowed to be positional and which are allowed to be named. I think the file can be either, but I don't think host is.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked! Thank you so much. I was missing the host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.