mongodb命令总结

 

发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.csdn.net/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.csdn.net/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件


————————————————

mongod –help  命令帮助
mongod  --dbpath path --auth  //启动服务
mongo –u username –p password  客户端连接

管理命令
use admin
db.addUser('admin','pwd') //增加用户
db.system.users.find()  //查看用户列表
db.auth('admin','pwd')   //用户认证
db.removeUser('mongodb')   //删除用户
show users			//查看所有用户
show dbs		//查看所有数据库
show collections	//查看所有的collection
db.printCollectionStats()  //查看各collection的状态
db.printReplicationInfo()   //查看主从复制状态
db.repairDatabase()	//修复数据库
db.setProfilingLevel(1)  //设置记录profiling,0=off 1=slow 2=all
show profile	//查看profiling
db.copyDatabase('mail_addr','mail_addr_tmp')  //拷贝数据库
db.mail_addr.drop()   //删除collection
db.dropDatabase()    //删除当前的数据库

增删改
db.foo.save({'name':'ysz','address':{'city':'beijing','post':100096},'phone':[138,139]})  //存储嵌套的对象
db.user_addr.save({'Uid':'yushunzhi@sohu.com','Al':['test-1@sohu.com','test-2@sohu.com']})   //存储数组对象

db.foo.update({'yy':5},{'$set':{'xx':2}},upsert=true,multi=true)
  //根据query条件修改,如果不存在则插入,允许修改多条记录
db.foo.remove({'yy':5}) //删除yy=5的记录
db.foo.remove() //删除所有的记录


索引
db.things.ensureIndex({firstname: 1, lastname: 1}, {unique: true});
//增加索引:1(ascending),-1(descending)
db.user_addr.ensureIndex({'Al.Em': 1})//索引子对象
db.deliver_status.getIndexes()  //查看索引信息
db.deliver_status.getIndexKeys()
db.user_addr.dropIndex('Al.Em_1')  //根据索引名删除索引
db.foo.dropIndexes()	


查询
db.foo.find()  //查找所有
db.foo.findOne() //查找一条记录
db.foo.find().skip(10)//跳过前10条记录
db.foo.find({'msg':'Hello 1'}).limit(10)// 根据条件检索10条记录
db.deliver_status.find({'From':'yushunzhi@sohu.com'}).sort({'Dt',-1})
// sort排序
db.deliver_status.find().sort({'Ct':-1}).limit(1)
db.user_addr.count()//count操作
db.foo.distinct('msg')// distinct操作
db.foo.find({"timestamp": {"$gte" : 2}})//>操作
db.foo.find({'address.city':'beijing'})//子对象的查找
查询条件表达式
$all,$exists,$mod,$ne,$in,$nin,$nor,$or,$and,$size,$type
db.things.find( { x : 3, y : "foo" } );
db.things.find({j: {$ne: 3}, k: {$gt: 10} });
db.collection.find({ "field" : { $lte: value } } ); 
db.collection.find({ "field" : { $gte: value } } );
db.collection.find({ "field" : { $lt: value } } );
db.collection.find({ "field" : { $gt: value1, $lt: value2 } } ); 
db.things.find( { a: { $all: [ 2, 3 ] } } );
db.things.find( { a : { $exists : true } } );
db.things.find( { a : { $mod : [ 10 , 1 ] } } )
db.things.find({j:{$in: [2,4,6]}});
db.things.find({j:{$nin: [2,4,6]}});
db.foo.find( { $or : [ { a : 1 } , { b : 2 } ] } )
db.foo.find( { $and: [ { a: 1 }, { a: { $gt: 5 } } ] }
db.things.find( { a : { $size: 1 } } );
db.things.find( { a : { $type : 2 } } ); // matches if a is a string
db.things.find( { a : { $type : 16 } } ); // matches if a is an int
db.customers.find( { name : { $regex : 'acme.*corp', $options: 'i' } } );


管理
db.deliver_status.dataSize()//查看collection数据的大小
db.deliver_status.stats() //查看colleciont状态
db.deliver_status.totalIndexSize()//查询所有索引的大小


MongoDB导入和导出
mongoexport --help  
mongoexport -d foo -c t1 -o /data/t1.json   
mongoimport --help   
mongoimport -d foo -c t1 /data/t1.json   

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值