MongoDB Import Script
#!/bin/shEcho"${0} Import data to MongoDB"Tagfile="/srv/mss_data/dim_customerex_mobile_stat_ ' Date +%y%m%d-d"-1 Day"'. Log"Impdatafile="/srv/mss_data/dim_customerex_mobile_stat_ ' Date +%y%m%d-d"-1 Day"'. txt"TableName="${1}"Echo"Tagfile:${tagfile}"Echo"Impdatafile:${impdatafile}"Echo"Tablename:${tablename}"if[-Z ${1}]; then echo"Please input tableName"Exit1Fiecho"Tagfile:${tagfile}"Echo"Impdatafile:${impdatafile}"if[-F"$impDataFile"-a-f"$tagFile"]; then line="$ (More ${tagfile})" Line="${line:0:1}" #take the first character #echo "' Expr length $line '" if[$line = ="1"]; then sed-I.'s/#//g'${impdatafile} MONGO Ods_mss--eval"Db.${tablename}.drop ()"Mongoimport-D ods_mss-c ${tablename}--type csv--headerline--file ${impdatafile} MONGO Ods_mss--eval"Db.${tablename}.ensureindex ({ec_custno:1,customerid:1,sex:1,lastlogdate:1,ismultidrawcash:1,isbookdshlvl:1 , Bankcount:1,vacco_shares:1,nonrt_shares:1,regular_treasure_shares:1,dshlvl_shares:1,thirdparty_shares:1, Finacingfund_shares:1,total_shares:1,vacco_capital:1,nonrt_capital:1,regular_treasure_capital:1,dshlvl_capital : 1,thirdparty_capital:1,finacingfund_capital:1,total_capital:1})"MONGO Ods_mss--eval"Db.${tablename}.find (). ForEach (function (doc) {doc.lastlogdate = new Date (doc.lastlogdate+ ' GMT-0800 (CST) ');d b.$ {Tablename}.save (DOC)});"fiElseEcho"file is not exists"fi
Second Edition:
#!/bin/shEcho"${0} Import data to MongoDB"Tagfile="/srv/mss_data/dim_customerex_mobile_stat_ ' Date +%y%m%d-d"-1 Day"'. Log"Impdatafile="/srv/mss_data/dim_customerex_mobile_stat_ ' Date +%y%m%d-d"-1 Day"'. txt"TableName="${1}"Echo"Tagfile:${tagfile}"Echo"Impdatafile:${impdatafile}"Echo"Tablename:${tablename}"if[-Z ${1}]; then echo"Please input tableName"Exit1Fiecho"Tagfile:${tagfile}"Echo"Impdatafile:${impdatafile}"if[-F"$impDataFile"-a-f"$tagFile"]; Then#line= "$ (more ${tagfile})"Eval $ (awk'{if (nr==1) print "line=" substr ($0,1,1)}'${tagfile}) echo $line; #line= "${line:0:1}" #取第一个字符Echo"' expr length $line '">>Mssadminlog.logif[$line = ="1"]; then sed-I.'s/#//g'${impdatafile}/srv/infra/mongodb/mongodb2.6.4/bin/mongo Ods_mss--eval"Db.${tablename}.drop ()"/srv/infra/mongodb/mongodb2.6.4/bin/mongoimport-d ods_mss-c ${tablename}--type csv--headerline--file ${impdatafile}/srv/infra/mongodb/mongodb2.6.4/bin/mongo Ods_mss--eval"Db.${tablename}.ensureindex ({ec_custno:1,customerid:1,sex:1,lastlogdate:1,ismultidrawcash:1,isbookdshlvl:1 , Bankcount:1,vacco_shares:1,nonrt_shares:1,regular_treasure_shares:1,dshlvl_shares:1,thirdparty_shares:1, Finacingfund_shares:1,total_shares:1,vacco_capital:1,nonrt_capital:1,regular_treasure_capital:1,dshlvl_capital : 1,thirdparty_capital:1,finacingfund_capital:1,total_capital:1})"Echo"Begin Date: ' Date '"MONGO Ods_mss--eval"Db.${tablename}.find (). ForEach (function (doc) {doc.lastlogdate = new Date (doc.lastlogdate);d b.table_2.update ({' _id ':d Oc._id},doc)});"Echo"End Date: ' Date '"Echo"Import Date ok!"fiElseEcho"file is not exists"fi
Other:
It seems that MONGO use eval when the command is "db." Beginning
ODS Project--mongodb Import Script