1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        面試官:說一下Redis和MongoDB的區(qū)別?

        共 5364字,需瀏覽 11分鐘

         ·

        2021-09-14 08:52

        項目中用的是MongoDB,但是為什么用其實當(dāng)時選型的時候也沒有太多考慮,只是認為數(shù)據(jù)量比較大,所以采用MongoDB。

        最近又想起為什么用MongoDB,就查閱一下,匯總匯總:

        之前也用過redis,當(dāng)時是用來存儲一些熱數(shù)據(jù),量也不大,但是操作很頻繁?,F(xiàn)在項目中用的是MongoDB,目前是百萬級的數(shù)據(jù),將來會有千萬級、億級。

        就Redis和MongoDB來說,大家一般稱之為Redis緩存、MongoDB數(shù)據(jù)庫。這也是有道有理有根據(jù)的,

        Redis主要把數(shù)據(jù)存儲在內(nèi)存中,其“緩存”的性質(zhì)遠大于其“數(shù)據(jù)存儲“的性質(zhì),其中數(shù)據(jù)的增刪改查也只是像變量操作一樣簡單;

        MongoDB卻是一個“存儲數(shù)據(jù)”的系統(tǒng),增刪改查可以添加很多條件,就像SQL數(shù)據(jù)庫一樣靈活,這一點在面試的時候很受用。

        Mongodb與Redis應(yīng)用指標(biāo)對比

        MongoDB和Redis都是NoSQL,采用結(jié)構(gòu)型數(shù)據(jù)存儲。二者在使用場景中,存在一定的區(qū)別,這也主要由于
        二者在內(nèi)存映射的處理過程,持久化的處理方法不同。MongoDB建議集群部署,更多的考慮到集群方案,Redis
        更偏重于進程順序?qū)懭?,雖然支持集群,也僅限于主-從模式。


        MongoDB語法與現(xiàn)有關(guān)系型數(shù)據(jù)庫SQL語法比較

         1MongoDB語法            MySql語法
        2
        3db.test.find({'name':'foobar'})             <==>          select * from test where name='foobar'
        4
        5db.test.find()                                      <==>          select *from test
        6
        7db.test.find({'ID':10}).count()             <==>          select count(*) from test where ID=10
        8
        9db.test.find().skip(10).limit(20)          <==>          select * from test limit 10,20
        10
        11db.test.find({'ID':{$in:[25,35,45]}})     <==>          select * from test where ID in (25,35,45)
        12
        13db.test.find().sort({'ID':-1})                 <==>          select * from test order by IDdesc
        14
        15db.test.distinct('name',{'ID':{$lt:20}}) <==>          select distinct(name) from testwhere ID<20
        16
        17db.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
        18
        19db.test.find('this.ID<20',{name:1})    <==>           select name from test whereID<20
        20
        21db.test.insert({'name':'foobar','age':25})    <==>       insertinto test ('name','age') values('foobar',25)
        22
        23db.test.remove({})                                     <==>       delete * from test
        24
        25db.test.remove({'age':20})                        <==>       delete test where age=20
        26
        27db.test.remove({'age':{$lt:20}})                <==>        delete test where age<20
        28
        29db.test.remove({'age':{$lte:20}})              <==>        delete test where age<=20
        30
        31db.test.remove({'age':{$gt:20}})              <==>         delete test where age>20
        32
        33db.test.remove({'age':{$gte:20}})            <==>         delete test where age>=20
        34
        35db.test.remove({'age':{$ne:20}})             <==>         delete test where age!=20
        36
        37db.test.update({'name':'foobar'},{$set:{'age':36}})<==> update test set age=36 where name='foobar'
        38
        39db.test.update({'name':'foobar'},{$inc:{'age':3}})<==> update test set age=age+3 where name='foobar'
        40
        41模糊查詢:$regex
        42
        43db.test.find({"name":{$regex:"aaa"}})
        44
        45分組個數(shù)過濾
        46
        47db.getCollection('id_mapper').aggregate([{$group:{ _id :"$contract_id",count:{$sum:1}}},{$match:{count:{$gt:1}}}])
        48
        49判斷是否為空
        50
        51db.getCollection('id_mapper').find({"sinocardid":{$in:[null]}})


        瀏覽 79
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            古风重口高h全肉bl男男 hezyo北岛玲办公室av在线 | 做爱网站现在观看 | 国产福利一区二区三区在线观看视频 | 三级伦理免费观看 | 色琪琪在线观看 | 好湿好紧太爽了公交车p站 | www.激情五月 | 中文字幕一区在线播放 | 国产精品久久久毛片无码电影 | 孕妇张开双腿任我玩 |