Skip to content

MongoDB insert script

Martin H. Bramwell edited this page Oct 16, 2015 · 3 revisions
export MONGO_SERVER="ds039684.mongolab.com"
export MONGO_PORT=39684
export MONGO_DB="ci4m"
export MONGO_UID="ci4m"
export MONGO_CONNECTION=${MONGO_SERVER}:${MONGO_PORT}/${MONGO_DB}
export MONGO_PATH=${MONGO_UID}:${MONGO_PWD}@${MONGO_CONNECTION}
export MONGO_URL=mongodb://${MONGO_PATH}


export REC01='{"text": "AA", "createdAt": new Date("04-16-2013")}'
export REC02='{"text": "BB", "createdAt": new Date("04-16-2013")}'
export INS01="[${REC01}, ${REC02}]"

if [[ "X${MONGO_PWD}X" = "XX" ]]; then
  echo "Would you like a password with that?.";
  exit 1;
fi;

function testMongoScript {
  mongo ${1} -u ${2} -p ${3} <<EOF
  db.tasks.insert( ${4} )
EOF
}

testMongoScript ${MONGO_CONNECTION} ${MONGO_UID} ${MONGO_PWD} "${INS01}"
Clone this wiki locally