從mongo導(dǎo)出數(shù)據(jù)
可以使用mongoexport,具體使用方法可參見(jiàn)mongo文檔
mongoexport -d test -c user -f id,name,createTime -q '{"status":{"$in":[0,1]}}' --csv -o out.csv
也可以使用腳本狠持,編寫(xiě)一個(gè)export.js腳本
db.user.find({"status":{"$in":[0,1]}}).forEach(function(user){
//var obj = eval('(' + comment.content + ')');
print(NumberInt(user.id).toNumber(),",",user.name,user.createTime);
});
然后執(zhí)行到處腳本
mongo test export.js > out.csv
導(dǎo)入數(shù)據(jù)到mysql
在mysql中可以使用load file導(dǎo)入數(shù)據(jù)区转,首先要選中目標(biāo)數(shù)據(jù)
user test;
load data infile '/tmp/out.csv' into table user character set utf8 fields terminated by ',' optionally enclosed by '"' escaped by '' lines terminated by '\n' ignore 2 lines;