隨筆-86  評(píng)論-33  文章-0  trackbacks-0
          MySQL:
              
          SELECT * FROM user
          Mongo:    
              db.
          user.find()


          MySQL:
              
          SELECT * FROM user WHERE name = 'foobar'
          Mongo:    
              db.
          user.find({'name' : 'foobar'})


          MySQL:
              
          INSERT INOT user (`name`, `age`) values ('foobar',25)
          Mongo:    
             db.
          user.insert({'name' : 'foobar''age' : 25})


          if you want add a  column `email` on MySQL,you must :
             
          ALTER TABLE user….
          But 
          in Mongo,you can just:    
            db.
          user.insert({'name' : 'foobar''age' : 25'email' : 'foo@bar.com'})


          MySQL:
              
          DELETE * FROM user
          Mongo:    
              db.
          user.remove({})


          MySQL:
              
          DELETE FROM user WHERE age < 30
          Mongo:    
              db.
          user.remove({'age' : {$lt : 30}})

          $gt : 
          > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=


          MySQL:
              
          UPDATE user SET `age` = 36 WHERE `name` = 'foobar'
          Mongo:    
              db.
          user.update({'name' : 'foobar'}, {$set : {'age' : 36}})


          MySQL:
              
          UPDATE user SET `age` = `age` + 3 WHERE `name` = 'foobar'
          Mongo:    
             db.
          user.update({'name' : 'foobar'}, {$inc : {'age' : 3}})

                  See more @ http:
          //www.mongodb.org/display/DOCS/Updating


          MySQL:
              
          SELECT COUNT(*FROM user WHERE `name` = 'foobar'
          Mongo:    
              db.
          user.find({'name' : 'foobar'}).count() 或 db.user.count({name:'foobar'});


          MySQL:
              
          SELECT * FROM user limit 10,20
          Mongo:    
             db.
          user.find().skip(10).limit(20)


          MySQL:
              
          SELECT * FROM user WHERE `age` IN (2535,45)
          Mongo:    
              db.
          user.find({'age' : {$in : [25, 35, 45]}})


          MySQL:
              
          SELECT * FROM user ORDER BY age DESC
          Mongo:    
              db.
          user.find().sort({'age' : -1})


          MySQL:
              
          SELECT DISTINCT(name) FROM user WHERE age > 20
          Mongo:    
             db.
          user.distinct('name', {'age': {$lt : 20}})


          MySQL:
              
          SELECT name, sum(marks) FROM user GROUP BY name
          Mongo:    
              db.
          user.group({
                  
          key : {'name' : true},
                  cond: {
          'name' : 'foo'},
                  reduce: 
          function(obj,prev) { prev.msum += obj.marks; },
                  initial: {msum : 
          0}
              });


          MySQL:
              
          SELECT name FROM user WHERE age < 20
          Mongo:    
             db.
          user.find('this.age < 20', {name : 1})
          posted on 2010-06-23 14:13 Derek.Guo 閱讀(726) 評(píng)論(0)  編輯  收藏 所屬分類: NoSqlDB

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          MSN:envoydada@hotmail.com QQ:34935442
          主站蜘蛛池模板: 花垣县| 平江县| 建德市| 东乌珠穆沁旗| 信宜市| 堆龙德庆县| 彰武县| 阳曲县| 云梦县| 册亨县| 新河县| 平乡县| 新营市| 浦东新区| 潼关县| 乌鲁木齐县| 建宁县| 黎川县| 虎林市| 朝阳区| 昂仁县| 黄梅县| 襄汾县| 绥江县| 鹤壁市| 深泽县| 铜川市| 巴林左旗| 天水市| 武鸣县| 逊克县| 建始县| 乌兰县| 义马市| 开远市| 格尔木市| 五原县| 进贤县| 嘉善县| 张家界市| 衡东县|