1netstat -nltp | grep 27017 #查看MongoDB端口 2./mongodb-start start # 启动 3./mongodb-stop stop #停止 4./mongo 127.0.0.1:27017 # 禁止auth后登陆MongoDB 5>show dbs; #显示数据库 6>db; # 显示当前数据库 7>use admin; # 转到数据库admin 8>db.auth('root','123456'); # 以用户名密码登录数据库 9
db.dis_specimen.remove({"barCode" : "201712212200"}) # 删除
db.par_func.find().count(); # 统计表par_func记录数
1function updateDelayDate() { 2 var details = db.dis_specimen_detail.find({ 3 "delayDate":{$ne:""} 4 }); 5 //var flag = false; 6 while (details.hasNext()) { 7 var detail = details.next(); 8 var date = detail.delayDate; 9 var id = detail._id; 10 if (date.length == 10) { 11 12 var newDate = date + " 00:00:00"; 13 db.dis_specimen_detail.updateOne({ 14 "_id" : id 15 }, { 16 $set : { 17 "delayDate" : newDate 18 } 19 }); 20 print("_id:"+id+",updated delayDate to "+newDate); 21 } 22 //flag = true; 23 } 24 //return flag; 25}; 26 27updateDelayDate();
// 更新表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) } )