Mongodb命令整理(待更新)

1、查询age = 20的记录

coll.find({age: 20});

2、查询age > 20的记录

coll.find({age: {$gt: 20}});

3、查询age < 20的记录

coll.find({age: {$lt: 20}});

4、查询age >= 20的记录

coll.find({age: {$gte: 20}});

5、查询age <= 20的记录

coll.find({age: {$lte: 20}});

6、查询age >= 20 并且 age <= 25

coll.find({age: {$gte: 20, $lte: 25}});

7、查询name中包含 olami的数据

coll.find({name:{$regex:"olami"}});

8、查询name中以olami开头的

coll.find({name:{$regex:"^olami"}});

9、查询name = olami, age = 20的数据

coll.find({name:”olami”, age: 20});

11、or与 查询

coll.find({$or: [{age: 22}, {age: 25}]});

12、创建索引

coll.createIndex({age: 1});

13、查询当前聚集集合所有索引

coll.getIndexes();

14、查看总索引记录大小

coll.totalIndexSize();

15、读取当前集合的所有index信息

coll.reIndex();

16、删除指定索引

coll.dropIndex("name_1");

17、删除所有索引索引

coll.dropIndexes();

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值