mongoDB常用命令整理

一、查询条件

where单个条件查询
db.test.find({"name":"mongoDB"})

and条件,简写

db.test.find({"name":"mongoDB","age":33})

and条件

db.test.find({"$and":[{"name":"mongoDB"},{"age":33}]})

or条件

db.test.find({"$or":[{"template_uid":"20200710C9L_s43Km"},{"editor_id":"704065"}]})

二、比较条件

等于就是where单个条件的查询
db.test.find({"age":20})
等于=:$eq
db.test.find({"age":{"$eq":20}})
大于>:$gt
db.test.find({"age":{"$gt":20}})
小于<:$lt
db.test.find({"age":{"$lt":20}})
大于等于>=:$gte
db.test.find({"age":{"$gte":20}})
小于等于<=:$lte
db.test.find({"age":{"$lte":20}})
不等于!=:$ne
db.test.find({"age":{"$ne":20}})
in条件
db.test.find({"age":{"$in":[20,21,22]}})
db.test.find({"name":{"$in":["张三","李四"]}})
like
db.test.find({"name":/张/})

三、增删改

删除,remove和deletemany
db.test.remove({"name":"张三"})
db.test.deleteMany({"name":"张三"})

持续更新中

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。