Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am writing a bash script which uses mongoimport utility to add data to the database.

The following command runs successfully:

$ mongoimport -h localhost:27017 -d test -c ecg --fieldFile data/ecg_fields --type csv --file data/temp_ecg_data

Next, I put it in a bash script as follows:

#!/bin/bash

HOST=$1
DATABASE=$2
COLLECTION=$3
FIELDFILE=$4
FIELDTYPE=$5
FILE=$6

mongoimport -h $HOST -d $DATABASE -c $COLLECTION --fieldFile $FIELDFILE --type $FILETYPE --file $FILE

Now, I get an error. Here is the output:

connected to: localhost:27017
Sat Dec 08 15:49:44 ERROR: don't know what type [--file] is

How do I fix this?

share|improve this question
add comment

1 Answer

You've mistakenly referred to FILETYPE not FIELDTYPE. Tweaked a bit:

#!/bin/bash

HOST=$1
DATABASE=$2
COLLECTION=$3
FIELDFILE=$4
FIELDTYPE=$5
FILE=$6

if [[ -z "$6" ]] ; then
   echo "Usage: ..." 1>&2
   exit 1
fi

mongoimport -h "$HOST" -d "$DATABASE" -c "$COLLECTION" --fieldFile "$FIELDFILE" --type "$FIELDTYPE" --file "$FILE"
share|improve this answer
1  
You should explain what you the condition does, too. –  Baarn Dec 8 '12 at 21:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.