MongoDB文法與現有關係型資料庫SQL文法比較

來源:互聯網
上載者:User

標籤:

進入,查看,使用

 

 進入  mongodb show dbsuse mydatabase show collections db["mycol"].find({},{_id:0,name:1})  # 第一個參數為條件,第二個參數為顯示結果設定 

db["mycol"].inseret({"key":"value",title:"tutorial",name:"jkmiao"})
 
MongoDB文法與現有關係型資料庫SQL文法比較MongoDB文法                                  MySql文法db.test.find({‘name‘:‘foobar‘})<==> select * from test where name=‘foobar‘db.test.find()                            <==> select *from testdb.test.find({‘ID‘:10}).count()<==> select count(*) from test where ID=10db.test.find().skip(10).limit(20)<==> select * from test limit 10,20db.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 IDdescdb.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 testdb.test.remove({‘age‘:20})            <==> delete test where age=20db.test.remove({‘age‘:{$lt:20}})   <==> elete test where age<20db.test.remove({‘age‘:{$lte:20}})  <==> delete test where age<=20db.test.remove({‘age‘:{$gt:20}})  <==> delete test where age>20db.test.remove({‘age‘:{$gte:20}})<==> delete test where age>=20db.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文法與現有關係型資料庫SQL文法比較

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.