ODS項目——mongoDB匯入指令碼

來源:互聯網
上載者:User

標籤:style   blog   color   io   使用   ar   strong   for   sp   

mongoDB匯入指令碼

#! /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"  exit 1fiecho "tagFile:${tagFile}"echo "impDataFile:${impDataFile}"if [ -f "$impDataFile" -a  -f "$tagFile" ] ;then    line="$(more ${tagFile})"    line="${line:0:1}"      #取第一個字元    #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)‘);db.${tableName}.save(doc)});"    fi else    echo "file is not exists"fi
 第二版:
#! /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"  exit 1fiecho "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.log    if [ $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);db.table_2.update({‘_id‘:doc._id},doc)});"        echo "end date:`date`"        echo "import date OK!"    fi else    echo "file is not exists"fi

 

另:

   好像mongo使用eval時命令都要以"db."開頭

 

ODS項目——mongoDB匯入指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.