少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          1.  超級用戶相關(guān):
          1. use admin
          2. #增加或修改用戶密碼
          3. db.addUser(ixigua,’pwd’)
          4. #查看用戶列表
          5. db.system.users.find()
          6. #用戶認證
          7. db.auth(ixigua,’pwd’)
          8. #刪除用戶
          9. db.removeUser(‘mongodb’)
          10. #查看所有用戶
          11. show users
          12. #查看所有數(shù)據(jù)庫
          13. show dbs
          14. #查看所有的collection
          15. show collections
          16. #查看各collection的狀態(tài)
          17. db.printCollectionStats()
          18. #查看主從復制狀態(tài)
          19. db.printReplicationInfo()
          20. #修復數(shù)據(jù)庫
          21. db.repairDatabase()
          22. #設置記錄profiling,0=off 1=slow 2=all
          23. db.setProfilingLevel(1)
          24. #查看profiling
          25. show profile
          26. #拷貝數(shù)據(jù)庫
          27. db.copyDatabase(‘mail_addr’,'mail_addr_tmp’)
          28. #刪除collection
          29. db.mail_addr.drop()
          30. #刪除當前的數(shù)據(jù)庫
          31. db.dropDatabase()
          2. 客戶端連接
          1. /usr/local/mongodb/bin/mongo 8.8.88/ixigualib -u ixigua -p ‘pwd’
          3. 增刪改
          1. #存儲嵌套的對象
          2. db.foo.save({‘name’:'ysz’,'address’:{‘city’:'beijing’,'post’:100096},’phone’:[138,139]})
          3. #存儲數(shù)組對象
          4. db.user_addr.save({‘Uid’:'yushunzhi@sohu.com’,'Al’:['test-1@sohu.com','test-2@sohu.com']})
          5. #根據(jù)query條件修改,如果不存在則插入,允許修改多條記錄
          6. db.foo.update({‘yy’:5},{‘$set’:{‘xx’:2}},upsert=true,multi=true)
          7. #刪除yy=5的記錄
          8. db.foo.remove({‘yy’:5})
          9. #刪除所有的記錄
          10. db.foo.remove()
          4. 索引
          1. #增加索引:1(ascending),-1(descending)
          2. db.things.ensureIndex({firstname: 1, lastname: 1}, {unique: true});
          3. #索引子對象
          4. db.user_addr.ensureIndex({‘Al.Em’: 1})
          5. #查看索引信息
          6. db.deliver_status.getIndexes()
          7. db.deliver_status.getIndexKeys()
          8. #根據(jù)索引名刪除索引
          9. db.user_addr.dropIndex(‘Al.Em_1′)
          5. 查詢
          1. #查找所有
          2. db.foo.find()
          3. #查找一條記錄
          4. db.foo.findOne()
          5. #根據(jù)條件檢索10條記錄
          6. db.foo.find({‘msg’:'Hello 1′}).limit(10)
          7. #sort排序
          8. db.deliver_status.find({‘From’:'ixigua@sina.com’}).sort({‘Dt’,-1})
          9. db.deliver_status.find().sort({‘Ct’:-1}).limit(1)
          10. #count操作
          11. db.user_addr.count()
          12. #distinct操作
          13. db.foo.distinct(‘msg’)
          14. #>操作
          15. db.foo.find({“timestamp”: {“$gte” : 2}})
          16. #子對象的查找
          17. db.foo.find({‘address.city’:'beijing’})
          6. 管理
          1. #查看collection數(shù)據(jù)的大小
          2. db.deliver_status.dataSize()
          3. #查看colleciont狀態(tài)
          4. db.deliver_status.stats()
          5. #查詢所有索引的大小
          6. db.deliver_status.totalIndexSize()

          posted on 2011-12-06 19:53 abin 閱讀(404) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 棋牌| 名山县| 郓城县| 衡南县| 吴桥县| 方山县| 万载县| 三门峡市| 南靖县| 衢州市| 靖宇县| 林西县| 耿马| 怀化市| 池州市| 灵山县| 乌拉特前旗| 滁州市| 航空| 扎鲁特旗| 江永县| 卓尼县| 高阳县| 珠海市| 华蓥市| 班玛县| 砚山县| 体育| 乌鲁木齐市| 萝北县| 航空| 永清县| 镇原县| 蒲城县| 八宿县| 万年县| 邢台市| 墨玉县| 鹰潭市| 时尚| 唐河县|