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)
    }
    )

  • 相关阅读:
    【WPF】 前言
    【设计模式】 建造者
    拖动调整显示框的显示区域大小
    HTTP权威指南
    input自动获取焦点
    元素JS拖动的实现
    手机端html5触屏事件(touch事件)
    使用".."指定git提交范围与"..."指定git提交范围的区别
    Long-term stable release maintenance
    MEMS--微机电系统
  • 原文地址:https://www.cnblogs.com/liuliu3/p/10033421.html
Copyright © 2011-2022 走看看