清理表数据,不清理索引
$ cat remove_table_data.sh
#!/bin/bash
db="test"
function mongo_login() {
/path/to/bin/mongo --quiet --host xx.xx.xx.xx --port=27017 -u username --password='XXX' --authenticationDatabase=admin
}
tables=`echo -e "use ${db};\n show tables;" | mongo_login | grep -v "switched to"`
for table in ${tables}
do
echo "##### ${table} #####"
echo -e "use ${db};\n db.${table}.remove({})" | mongo_login
done
网友评论