guanxf

          我的博客:http://blog.sina.com.cn/17learning

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            71 隨筆 :: 1 文章 :: 41 評論 :: 0 Trackbacks
          1、編寫腳步:update.js
               /**
           * 時間對象的格式化;
           */
          Date.prototype.format = function(format) {
              /*
               * eg:format="YYYY-MM-dd hh:mm:ss";
               */
              var o = {
                  "M+" :this.getMonth() + 1, // month
                  "d+" :this.getDate(), // day
                  "h+" :this.getHours(), // hour
                  "m+" :this.getMinutes(), // minute
                  "s+" :this.getSeconds(), // second
                  "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
                  "S" :this.getMilliseconds()
              // millisecond
              }
           
              if (/(y+)/.test(format)) {
                  format = format.replace(RegExp.$1, (this.getFullYear() + "")
                          .substr(4 - RegExp.$1.length));
              }
           
              for ( var k in o) {
                  if (new RegExp("(" + k + ")").test(format)) {
                      format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
                              : ("00" + o[k]).substr(("" + o[k]).length));
                  }
              }
              return format;
          }
          var date =new Date();
          var createdate=date.format("yyyy-MM-dd hh:mm:ss");
          date.setMinutes(date.getMinutes()+5);
          var validtime=date.format("yyyy-MM-dd hh:mm:ss");
          db.UserOnlineInfo.update(
          {
            "uid" : "110000350"
          },
          {$set : {
            "uid" : "110000350", 
            "createtime" : createdate,
            "validtime" : validtime
          }});
          db.UserOnlineInfo.update(
          {
            "uid" : "110000351"
          },
          {$set : {
            "uid" : "110000351", 
            "createtime" : createdate,
            "validtime" : validtime
          }});

          2、編寫shell腳步:
           #/bin/bash
          echo "update mongod begin"
          cd /home/mongodb/mongodb-3.0.2/bin
          ./mongo  192.168.1.122:27108/YouLiao update.js;
          echo "update mongod success"

          3、 執行腳本:
          /home/mongodb/mongodb-3.0.2/bin/mongo  192.168.1.122:27108/YouLiao /root/www/job/mongo-test/update.js

          備注:
          mongodb查詢、刪除類似

             
          posted on 2015-09-22 19:25 管先飛 閱讀(3570) 評論(0)  編輯  收藏 所屬分類: Database
          主站蜘蛛池模板: 萨嘎县| 寻乌县| 元谋县| 陵川县| 新泰市| 治县。| 连城县| 钟山县| 柳林县| 哈密市| 克东县| 宁安市| 昌邑市| 老河口市| 三亚市| 措美县| 仁布县| 禄丰县| 高要市| 丰城市| 威海市| 萝北县| 耿马| 麦盖提县| 铜川市| 江西省| 通榆县| 乳源| 名山县| 济阳县| 佛坪县| 马鞍山市| 西贡区| 惠东县| 昌都县| 印江| 靖江市| 分宜县| 灌阳县| 新龙县| 丹寨县|