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