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?
case "$i" in *shop*)echo $i;;esac... note the double quotes around $i, in case of odd characters