要求
1.导入时数据批量写设置为100, 且导入失败则报错中止;
2.student表导入命令在Linux命令行下执行,class表的导入命令放到Shell脚本中执行;
第一步:创建表
//创建student表
db.pratice4.createCL("student",{ShardingKey:{sid:1},ShardingType:"hash"})
//创建class表
db.pratice4.createCL("class",{ShardingKey:{cid:1},ShardingType:"hash"})
第二步:查看源数据csv文件
#查看student.csv文件
cat /opt/sequoiadb/student.csv
#查看class.csv文件
cat /opt/sequoiadb/class.csv
第三步:Linux导入
#在sdbadmin用户下导入数据到student表当中
bin/sdbimprt -c pratice4 -l student --file /opt/sequoiadb/student.csv --fields "sid int,sname String,sage String,ssex String,cid String,sprovince String,scity String,sphone String,semail String" --headerline true -n 100 --errorstop true
//查看student集合中存在的记录数量
db.pratice4.student.count()
第四步:shell脚本导入
#创建shell脚本class.sh
vi /opt/sequoiadb/class.sh
Shell脚本具体内容如下:
bin/sdbimprt -c pratice4 -l class --file /opt/sequoiadb/class.csv --fields "cid int,cname String,avgsChinese String,avgsMath String,avgsEnglish String,avgsBiology String,avgsChemistry String,avgsPhysics String" --headerline true -n 100 --errorstop true
#运行脚本
./class.sh
//查看class集合中存在的记录数量
db.pratice4.class.count()