Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Guys,
- I want to modify this script so that it does not open mongo connection in each loop
- # cat names.txt
- Robert
- Salim
- James
- Kolja
- Manfred
- *********************8
- #!/bin/bash
- MONGO_DBUSER='admin'
- MONGO_DBPASS='admin123'
- MONGO_SLAVE_SERVER='192.168.1.5'
- MONGO_DB='students'
- MONGO_COLLECTION='college'
- while read -r names; do
- $(which mongo) --host=$MONGO_SLAVE_SERVER -u $MONGO_DBUSER -p $MONGO_DBPASS --authenticationDatabase admin --port 27017 --quiet $MONGO_DB <<EOF
- rs.slaveOk()
- db.${MONGO_COLLECTION}.find({"name" : "${names}"},{name: 1, location: 1, _id: 0});
- EOF
- done < names.txt | perl -ne 'print "$1,$2\n" if /"name" : "([^"].*)", "location" : "([^"].*)"/' > name_location.csv
- ************************
- so I tried this but it is not working. csv file is not generating
- *************************************
- #!/bin/bash
- MONGO_DBUSER='admin'
- MONGO_DBPASS='admin123'
- MONGO_SLAVE_SERVER='192.168.1.5'
- MONGO_DB='students'
- MONGO_COLLECTION='college'
- exec 4> >(mongo --host=$MONGO_SLAVE_SERVER --port 27017 --quiet $MONGO_DB)
- while read -r names; do
- echo "db.${MONGO_COLLECTION}.find({"names" : \"${names}\"},{names: 1, location: 1, _id: 0})" >&4
- done < names.txt | perl -ne 'print "$1,$2\n" if /"name" : "([^"].*)", "location" : "([^"].*)"/' > name_location.csv
- **********************************
Add Comment
Please, Sign In to add comment