Here im trying to push some values to mongodb this is my pseudo code
while read LINE
do
addRow $para1 $param1 #pass value to the mongo
done < ${FILE}
function addRow() {
para1="$1";
para2="$2";
if [ ! -z "$para1" ]
then
echo $1 $2;
mongo dbname <<EOF
newstuff = [{ "name" : "${1}", "age" : "${2}" }]
db.collectionname.insert(newstuff);
EOF
else
echo “Failed”;
fi
}
Its working fine, but i think that's not a proper way to do that job, i can see connect was re establish every time, any expertise suggestions may helpful
#### Process
bye
#file1
connecting to: dbname
[
##proc 1
]
bye
#file 2
MongoDB shell version: 2.4.8
connecting to: dbname
[
##proc 2
]
bye
#file3
MongoDB shell version: 2.4.8
connecting to: dbname
[
##proc 3
]
bye