mongo 数据导入导出脚本

#!/bin/bash
i=0;
while read line
do
echo "/*****************************************************************/"
echo "===========start to import data for user $line===================="
mongoexport --host 172.0.0.12 --port 27017 --db www --username user --password user --collection playlist --query "{ UserId: { \$gte: $line , \$lte:$line}}" --out ./playlist$1.dat
mongoexport --host 172.0.0.12 --port 27017 --db www --username user --password user --collection playlistreview --query "{ UserId: { \$gte: $line , \$lte:$line}}" --out ./playlistreview$1.dat
mongoexport --host 172.0.0.12 --port 27017 --db www --username user --password user --collection homeworkcenter --query "{ UserId: { \$gte: $line , \$lte:$line}}" --out ./homeworkcenter$1.dat
mongoexport --host 172.0.0.12 --port 27017 --db www --username user --password user --collection homeworkcenterreview --query "{ UserId: { \$gte: $line , \$lte:$line}}" --out ./homeworkcenterreview$1.dat

mongoimport -j 4 --host 172.0.0.11 --port 27017 --authenticationDatabase staging --db staging --username staging --password Welcome123 -c playlist ./playlist$1.dat
mongoimport -j 4 --host 172.0.0.11 --port 27017 --authenticationDatabase staging --db staging --username staging --password Welcome123 -c playlistreview ./playlistreview$1.dat
mongoimport -j 4 --host 172.0.0.11 --port 27017 --authenticationDatabase staging --db staging --username staging --password Welcome123 -c homeworkcenter ./homeworkcenter$1.dat
mongoimport -j 4 --host 172.0.0.11 --port 27017 --authenticationDatabase staging --db staging --username staging --password Welcome123 -c homeworkcenterreview ./homeworkcenterreview$1.dat
echo "===========finish importing data for user $line===================="

rm *$1.dat;
i=`expr $i + 1`;
echo "===========processing the No#$i item =============================="
echo "/*****************************************************************/"
done < $1

你可能感兴趣的:(mongo 数据导入导出脚本)