zoukankan      html  css  js  c++  java
  • MongoDB常用SQL

    netstat -nltp | grep 27017    #查看MongoDB端口
    ./mongodb-start start    # 启动
    ./mongodb-stop stop    #停止
    ./mongo 127.0.0.1:27017    # 禁止auth后登陆MongoDB
    >show dbs;    #显示数据库
    >db;    # 显示当前数据库
    >use admin;    # 转到数据库admin
    >db.auth('root','123456');     # 以用户名密码登录数据库
    
    

    db.dis_specimen.remove({"barCode" : "201712212200"}) # 删除

    db.par_func.find().count(); # 统计表par_func记录数

    function updateDelayDate() {
    	var details = db.dis_specimen_detail.find({
    		"delayDate":{$ne:""}
    	});
    	//var flag = false;
    	while (details.hasNext()) {
    		var detail = details.next();
    		var date = detail.delayDate;
    		var id = detail._id;
    		if (date.length == 10) {
    
    			var newDate = date + " 00:00:00";
    			db.dis_specimen_detail.updateOne({
    				"_id" : id
    			}, {
    				$set : {
    					"delayDate" : newDate
    				}
    			});
    			print("_id:"+id+",updated delayDate to "+newDate);
    		}
    		//flag = true;
    	}
    	//return flag;
    };
    
    updateDelayDate();
    

    // 更新表par_customer中name以yi开头的记录,把active字段值更新为0
    db.getCollection('par_customer').find({"name":/^yi/}).forEach(function(item){
    db.getCollection('par_customer').update({"_id":item._id},{$set:{"active": "0"}})
    })

    // 更新表test_item_price中"standardPrice":null的数据为66
    db.test_item_price.find({"standardPrice":null}).forEach(
    function(item){
    db.test_item_price.update({"_id" : item._id},{"$set":{"standardPrice":66}},false,true)
    }
    )

  • 相关阅读:
    [bzoj1934][Shoi2007]Vote 善意的投票
    [bzoj1834][ZJOI2010]network 网络扩容
    [bzoj2127]happiness
    [bzoj3876][Ahoi2014]支线剧情
    [bzoj1927][Sdoi2010]星际竞速
    [bzoj3223]Tyvj 1729 文艺平衡树
    [bzoj3224]Tyvj 1728 普通平衡树
    FJOI2017 RP++
    [bzoj3529][Sdoi2014]数表
    异步ajax请求数据处理
  • 原文地址:https://www.cnblogs.com/liuliu3/p/10033421.html
Copyright © 2011-2022 走看看