mongodb类比关系型数据库的写法

本篇笔记记录:mongodb类比关系型数据库语句写法;
1,查询
查询集合中所有:

mongomysql
db.getCollection(“deviceLog_20190118”).find({})select * from user
1.1  查询:
查询方式mongomysql
"eq”db.getCollection(“deviceLog_20190118”).find({“sn”:“585d48c52f6686b6”})select * from user where user_name = ‘ming’
“like”db.getCollection(“deviceLog_20190118”).find({“sn”:{"$regex":/585d48/}})select * from user where user_name like ‘%ming%’
db.getCollection(“deviceLog_20190118”).find({“sn”:{"$regex":/^585d48/}})select * from user where user_name like ‘ming%’
“distinct”db.getCollection(“deviceLog_20190118”).distinct(“sn”)select distinct(user_name) from user
anddb.getCollection(“deviceLog_20190118”).find({“sn”:“585d48c52f6686b6”,“severity”:“1”})select * from user where user_name = ‘ming’ and user_id = ‘1’
db.getCollection(“deviceLog_20190118”).find({“sn”:“585d48c52f6686b6”,“severity”:“1”},{“sn”:1,“severity”:1,“dspMsg”:1})select user_name,user_id,user_age from user where user_name = ‘ming’ and user_id = ‘1’
“or”db.getCollection(“deviceLog_20190118”).find({ “$or”: [{“sn”:“585d48c52f6686b6”},{“severity”:“1”}] },{“sn”:1,“severity”:1,“dspMsg”:1})select user_name,user_id,user_age from user where user_name = ‘ming’ or user_id = ‘1’
<, <=, >, >= ($lt, $lte, $gt, $gte )db.getCollection(“deviceLog_20190118”).find({ “score”:{“ g t e &quot; : 20 , &quot; gte&quot;:20,&quot; gte":20,"lte”:30} })select * from user where user_age >=20 and user_age<=30
in, not in ($in, $nin)db.getCollection(“deviceLog_20190118”).find({ “score”:{"$in": [20,30,40]} })select * from user where user_age in (20,30,40);
“count”db.getCollection(“deviceLog_20190118”).count()select count(1) from user
不等于 $nedb.getCollection(“deviceLog_20190118”).find({ “score”:{"$ne": 20} })select * from user where user_age != 20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值