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
          主站蜘蛛池模板: 敖汉旗| 余江县| 雅安市| 两当县| 陆河县| 衡水市| 东阿县| 吴川市| 特克斯县| 灌南县| 万安县| 屏南县| 仪征市| 固阳县| 澎湖县| 伊宁市| 甘肃省| 措勤县| 长岛县| 镶黄旗| 房产| 宾阳县| 嘉祥县| 怀远县| 克什克腾旗| 巴彦县| 伽师县| 廉江市| 嘉义县| 项城市| 泽库县| 东山县| 隆子县| 秀山| 宁晋县| 上思县| 宝兴县| 盈江县| 新营市| 石嘴山市| 河北省|