mongo简单操作

来源:互联网 发布:ubuntu中文五笔输入法 编辑:程序博客网 时间:2024/06/07 07:29
1、阿里云给mongo数据库添加访问ip
云服务器ECS---运行中---服务器--(右边)管理---本实例安全组--配置规则--公网入方向--克隆--ip--ok




删除数据 db.getCollection('bs_live_msg').remove({"insertTime":{"$lt":new Date("2016/12/01")}}


db.getCollection('bs_user').find({userNickName:'游客MY55VOg0'})


模糊查询db.UserInfo.find({userName :/A/})


LIKE "A%"模糊查询  db.UserInfo.find({userName :/^A/})


删除
db.bs_user.remove({'userNickName':/^游客/})




db.bs_user.group({
 keyf : function(doc){
var date = new Date(doc.insertTime);
var dateKey = ""+date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
return {'day':dateKey}; 
}, 
condition:{userNickName:/^游客/,userType:1},
 initial : {"count":0}, 
 reduce : function Reduce(doc, out) {
            if(doc.userNickName){
out.count +=1;
            }
}
});






数据备份 


cd  F:\Program Files\MongoDB\Server\3.2\bin (到mongo的安装目录下)


单个数据库备份
123.123.123.xxx:27010  ip:端口
hzvip-test数据库名  
mongodump -h 123.123.123.xxx:27017  -d liveshow-ede-sc -o e:/ede


单个数据库备份还原
mongorestore -h 123.123.123.xxx:27017 -d liveshow-ede-sc e:/ede --drop


mongorestore -h 123.123.123.xxx :27017 -d liveshow-data e:/ede/liveshow-ede-sc


单collection备份
mongoexport -h 123.123.123.xxx:27010 -d hzvip-test -c bms_employees  -o e:\bms_employees.data


单collection还原
mongoimport -h 123.123.123.xxx:27010 -d hzvip-test -c bms_employees   e:\bms_employees.data







原创粉丝点击