[mongodb]常用命令备忘(持续更新中…)

常见问题

从库无法访问

not master and slaveOk=false

登录从库提示,not master and slaveOk=false,可手动设置从库可用

db.getMongo().setSlaveOk()

常见命令

查询数据库

show databases;

查询集合

show collections;

查询全部

db.getCollection("集合名称").find({})

等值查询

db.getCollection("集合名称").find({"字段名":"字段值"})

多条件查询

db.getCollection("集合名称").find({"字段名1":"字段值1","字段名2":"字段值2"})

OR查询

db.getCollection("集合名称").find({$or:[{"字段名1":"字段值1","字段名2":"字段值2"}]})

包含查询

db.getCollection("集合名称").find({$where:"this.字段名.indexOf('字段内容')>-1"})

索引查询

db.getCollection("集合名称").getIndexes()

排序

-1: 降序;1:升序

db.getCollection("集合名称").find({"字段名":"字段值"}).sort("字段名":-1)

分页

-1: 降序;1:升序

db.getCollection("集合名称").find({"字段名":"字段值"}).sort("字段名":-1).skip(游标值).limit(页大小)

执行计划

db.getCollection("集合名称").find({$where:"this.字段名.indexOf('字段内容')>-1"}).explain()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值