Tuesday, 13 August 2013

Bash string compare cannot match

Bash string compare cannot match

I want to filter some collections in mongodb to export. But the string
compare seems incorrect.
$1 in my case is localhost:17017/mydb
shop is one of the collections in mongodb, but $i == 'shop' never succeed.
#!/bin/bash
colls=`mongo $1 --eval 'db.getCollectionNames();' | tail -1`
IFS=',' read -ra ADDR <<< $colls
for i in "${ADDR[@]}"
do
if [[ $i == 'shop' ]]
then
echo $i
fi
done
Or is there any other methods to export specified collections from mongodb?

No comments:

Post a Comment