MongoDB语法 | MySql语法 |
---|---|
db.test.find({'name':'foobar'}) | select * from test where name='foobar' |
select * from test where name='foobar' | select *from test |
db.test.find({'ID':10}).count() | select count(*) from test where ID=10 |
db.test.find({'ID':10}).count() | select count(*) from test where ID=10 |
db.test.find().skip(10).limit(20) | select * from test limit 10,20 |
db.test.find({'ID':{$in:[25,35,45]}}) | select * from test where ID in (25,35,45) |
db.test.find().sort({'ID':-1}) | select * from test order by IDdesc |
db.test.distinct('name',{'ID':{$lt:20}}) | select distinct(name) from testwhere ID<20 |
db.test.group({key:{'name':true},cond:{'name':'foo'},reduce:function(obj,prev){prev.msum+=obj.marks;},initial:{msum:0}}) | select name,sum(marks) from testgroup by name |
db.test.find('this.ID<20',{name:1}) | select name from test whereID<20 |
db.test.insert({'name':'foobar','age':25}) | insertinto test ('name','age') values('foobar',25) |
db.test.remove({}) | delete * from test |
db.test.remove({'age':20}) | delete test where age=20 |
db.test.remove({'age':{$lt:20}}) | delete test where age<20 |
db.test.remove({'age':{$lte:20}}) | delete test where age<=20 |
db.test.remove({'age':{$gt:20}}) | delete test where age>20 |
db.test.remove({'age':{$gte:20}}) | delete test where age>=20 |
db.test.remove({'age':{$ne:20}}) | delete test where age!=20 |
db.test.update({'name':'foobar'},{$set:{'age':36}}) | update test set age=36 where name='foobar' |
db.test.update({'name':'foobar'},{$inc:{'age':3}}) | update test set age=age+3 where name='foobar' |
MongoDB语法与MySql语法对比
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 1.更高的写入负载 默认情况下,MongoDB更侧重高数据写入性能,而非事务安全,MongoDB很适合业务系统中有...