狼愛上貍

          我胡漢三又回來了

          #

          mongo數據庫的下載與安裝(windows xp環境下)

          1.下載數據庫http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip

          2.現在完成后解壓目錄,放到C盤下,然后按照如下選擇“我的電腦->屬性->高級->環境變量”,將“C:\mongodb\bin”這個路徑放到環境變量內(如果添加環境變量可以去網上找).

          3.選擇"開始->運行",輸入"cmd",在DOS窗口內輸入“mongod -port 27017 -dbpath D:/deployment/mongoDb/data/db -logpath D:/deployment/mongoDb/data/log/logs.log ”,其中dbpath 為數據文件存儲路徑,logpath 為日志文件存儲路徑。

          4.不要關閉上面的窗口,新打開一個DOS,輸入“mongo->use admin->db.AddUser(username,password)”,username:數據庫數據集的用戶名,password數據庫數據集操作的密碼。

          5.在兩個DOS窗口內分別按“ctrl+c”,在第一個DOS窗口內輸入“mongod -port 27017 -dbpath D:/deployment/mongoDb/data/db -logpath D:/deployment/mongoDb/data/log/logs.log -logappend -auth”的啟動命令,auth是要求操作數據集是需要驗證。

          6.在第二個DOS窗口內,輸入“mongo->use admin->db.auth(username,password)”,然后就可以對數據集進行操作(增、刪、改)。


          來自:http://www.hitb.com.cn/web/guest/bbs/-/message_boards/message/26944

          posted @ 2011-03-23 11:00 狼愛上貍 閱讀(956) | 評論 (0)編輯 收藏

          win7 啟動 mongo 方案

          http://www.360doc.com/content/10/0618/22/10626_33885376.shtml

          posted @ 2011-03-23 10:32 狼愛上貍 閱讀(372) | 評論 (0)編輯 收藏

          mongo 命令集

          首先在mongo官網下載Windows的版本 

          啟動服務:mongod.exe --port 12345 --dbpath=c:\mongodb\db 
          顯示一下信息: 
          Fri Dec 04 14:30:32 Mongo DB : starting : pid = 0 port = 12345 dbpath = c:\mongo 
          db\db master = 0 slave = 0  32-bit 

          ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 

          **       see http://blog.mongodb.org/post/137788967/32-bit-limitations for more 

          Fri Dec 04 14:30:32 db version v1.1.4-, pdfile version 4.5 
          Fri Dec 04 14:30:32 git version: c67c2f7dd681152f1784c8e1c2119b979e65881d 
          Fri Dec 04 14:30:32 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI 
          B_VERSION=1_35 
          Fri Dec 04 14:30:32 waiting for connections on port 12345 


          啟動客戶端:mongo.exe localhost:12345 

          檢查是否正常:db.foo.save({a:1,b:9}) 
               db.foo.find({a:1}) 
          控制臺顯示:{ "_id" : ObjectId("4b18b5b56f40000000006cec"), "a" : 1, "b" : 9 } 


          添加數據:db.foo.save({a:1,b:9}) 

          查詢數據:db.foo.find({a:1})  //{a:1}是查詢條件,當為空時查詢所有 
            db.foo.findOne({a:1}) //顯示出一條數據 

          刪除數據:db.foo.remove({a:1}) //刪除a=1的數據 

          表的數據量:db.foo.find().count() 

          顯示數據指定的條數:db.foo.find().limit(n) 

          顯示庫名:db.foo.getDB() 

          獲取索引值:db.foo.getIndexes() 

          表的統計:db.foo.stats() 

          刪除表:db.foo.drop() 

          獲取不重復的列:db.foo.distinct( key ) - eg. db.foo.distinct( 'x' ) 

          忽略前面的幾行:db.other.find({a:2}).skip(2)//忽略a=2中的前面2行 

          方法幫助:db.foo.help() 


          HELP 
                  show dbs                     show database names 
                  show collections             show collections in current database 
                  show users                   show users in current database 
                  show profile                 show most recent system.profile entries with time >= 1ms 
                  use <db name>                set curent database to <db name> 
                  db.help()                    help on DB methods 
                  db.foo.help()                help on collection methods 
                  db.foo.find()                list objects in collection foo 
                  db.foo.find( { a : 1 } )     list objects in foo where a == 1 
                  it                           result of the last line evaluated; use to further iterate 


          DB methods: 
                  db.addUser(username, password) 
                  db.auth(username, password) 
                  db.cloneDatabase(fromhost) 
                  db.commandHelp(name) returns the help for the command 
                  db.copyDatabase(fromdb, todb, fromhost) 
                  db.createCollection(name, { size : ..., capped : ..., max : ... } ) 
                  db.currentOp() displays the current operation in the db 
                  db.dropDatabase() 
                  db.eval(func, args) run code server-side 
                  db.getCollection(cname) same as db['cname'] or db.cname 
                  db.getCollectionNames() 
                  db.getLastError() - just returns the err msg string 
                  db.getLastErrorObj() - return full status object 
                  db.getMongo() get the server connection object 
                  db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair 
                  db.getName() 
                  db.getPrevError() 
                  db.getProfilingLevel() 
                  db.getReplicationInfo() 
                  db.getSisterDB(name) get the db at the same server as this onew 
                  db.killOp() kills the current operation in the db 
                  db.printCollectionStats() 
                  db.printReplicationInfo() 
                  db.printSlaveReplicationInfo() 
                  db.printShardingStatus() 
                  db.removeUser(username) 
                  db.repairDatabase() 
                  db.resetError() 
                  db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 } 
                  db.setProfilingLevel(level) 0=off 1=slow 2=all 
                  db.shutdownServer() 
                  db.version() current version of the server 

          DBCollection help 
                  db.foo.count() 
                  db.foo.dataSize() 
                  db.foo.distinct( key ) - eg. db.foo.distinct( 'x' ) 
                  db.foo.drop() drop the collection 
                  db.foo.dropIndex(name) 
                  db.foo.dropIndexes() 
                  db.foo.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups 
                  db.foo.find( [query] , [fields]) - first parameter is an optional queryfilter. second parameter is optional set of fields to return.  e.g. db.foo.find( { x : 77 } , { name : 1 , x : 1 } ) 
                  db.foo.find(...).count() 
                  db.foo.find(...).limit(n) 
                  db.foo.find(...).skip(n) 
                  db.foo.find(...).sort(...) 
                  db.foo.findOne([query]) 
                  db.foo.getDB() get DB object associated with collection 
                  db.foo.getIndexes() 
                  db.foo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } ) 
                  db.foo.mapReduce( mapFunction , reduceFunction , <optional params> ) 
                  db.foo.remove(query) 
                  db.foo.renameCollection( newName ) renames the collection 
                  db.foo.save(obj) 
                  db.foo.stats() 
                  db.foo.storageSize() - includes free space allocated to this collection 
                  db.foo.totalIndexSize() - size in bytes of all the indexes 
                  db.foo.totalSize() - storage allocated for all data and indexes 
                  db.foo.update(query, object[, upsert_bool]) 
                  db.foo.validate() - SLOW 
                  db.foo.getShardVersion() - only for use with sharding 

          來自: http://canofy.javaeye.com/blog/540926

          posted @ 2011-03-23 10:31 狼愛上貍 閱讀(2154) | 評論 (0)編輯 收藏

          mongo shell命令

          命令行

          --help 顯示命令行參數
          --nodb 不連接數據庫方式啟動,稍后可以使用 new Mongo() 或 connect() 來建立連接
          --shell 從命令行運行完一個 .js 文件后,停留在shell中,而不是結束

          特殊命令

          非JavaScript的輔助指令:

          help 顯示幫助
          db.help() 顯示 db 方法幫助
          db.myColl .help() 顯示聚集的方法幫助
          show dbs 打印服務器上所有數據庫的列表
          use dbname 設置db變量來指明使用服務器上的 dbname 數據庫
          show collections 打印當前數據庫的所有聚集
          show users 打印當前數據庫的用戶
          show profile 打印最近耗時大于1ms的profiling操作

          基本的Shell Javascript操作

          db 指向當前數據庫對象和連接的變量,已經在你的實例里定義好。
          db.auth(user,pass) 數據庫認證(如果運行安全模式的話)
          coll = db.collection 訪問數據庫里特定的 collection
          cursor = coll.find() 查找聚集里所有的對象。參考 [查詢] 。
          coll.remove(objpattern ) 從聚集里刪除匹配的對象。 
          objpattern 是一個指定匹配的域的對象,例如:coll.remove( { name: "Joe" } );
          coll.save(object ) 在聚集中保存對象,如果已經存在的話則更新它。 
          如果對象有 presave 方法,則會在保存到數據庫之前(插入和更新之前)調用該方法。
          coll.insert(object) 向聚集中插入對象。不會檢查該對象是否已經存在聚集中(即,不是 upsert)
          coll.update(...) 在聚集中更新對象。update() 有許多參數,請查看 更新 文檔。
          coll.ensureIndex( { name : 1 } ) 對 name 建索引。如果索引存在則不做任何事。
          coll.drop() 刪除 coll 聚集
          db.getSisterDB(name) 返回當前連接的另一個數據庫。它允許跨數據庫查詢,例如:db.getSisterDB('production').getCollectionNames()

          查詢

          coll.find() 查詢所有文檔
          it 循環上次 find() 調用返回的游標
          coll.find( criteria ); 查詢聚集中匹配 criteria 的對象。例如:coll.find( { name: "Joe" } );
          coll.findOne( criteria); 查詢并返回一個對象。如果沒有找到則返回 null。如果你只需要返回一個對象,這個方法比 find() as limit(1) 效率更高。如果元素類型是字符串,數字或時間,你還可以使用正則表達式:coll.find( { name: /joe/i } );
          coll.find( criteria, fields ); 查詢對象里特定的域。例如:coll.find( {}, {name:true} );
          coll.find().sort( {field :1[, field :1] }); 對返回結果進行排序(field ASC)。使用 -1 表示 DESC。
          coll.find( criteria ).sort( { field : 1 } ) 查找匹配 criteria 的對象,并對 field 進行排序。
          coll.find( ... ).limit(n ) 限制結果返回 n 行。如果你只需要某幾行數據,推薦這樣做來獲得最優性能。
          coll.find( ... ).skip(n) 跳過 n 行結果。
          coll.count() 返回聚集里對象的總數。
          coll.find( ... ).count() 返回匹配該查詢的對象總數。注意,該返回會忽略 limit 和 skip。比如有100行記錄匹配該查詢,但是limit為10,count() 仍會返回100。這比你自己循環更快,但仍然需要消耗些時間。

          更多信息請參考 [查詢] 。

          錯誤檢查

          [{{db.getLastError()}}] 返回上次操作的錯誤
          db.getPrevError() 返回之前操作的錯誤
          db.resetError() 清除錯誤記錄

          管理命令

          db.cloneDatabase(fromhost) 從另外指定的主機拷貝當前數據數據庫。fromhost必須為noauth模式。
          db.copyDatabase(fromdb, todb, fromhost) 拷貝fromhost的fromdb數據庫到當前服務器的todb數據庫。fromhost必須為noauth模式。
          db.repairDatabase() 修復當前數據庫。如果數據庫很大則該操作會非常慢。
          db.addUser(user,pwd) 給當前數據庫添加用戶。
          db.getCollectionNames() 獲得所有聚集的列表。
          db.dropDatabase() 刪除當前數據庫。

          打開額外連接

          db = connect("<host>:<port>/<dbname>") 打開一個新的數據庫連接。一個shell可能有多個連接,但是shell自動的getLastError只用于 'db' 變量。
          conn = new Mongo("hostname") 打開一個新的服務器連接。然后可以使用 getDB() 來選擇一個數據庫。
          db = conn.getDB("dbname") 對一個連接選擇一個特定的數據庫。

          其他

          Object.bsonsize(db.foo.findOne()) 打印一個數據庫對象的bson大小(mongo 版本1.3及以上)
          db.foo.findOne().bsonsize() 打印一個數據庫對象的bson大小 (mongo 版本1.3之前)

          posted @ 2011-03-23 10:29 狼愛上貍 閱讀(8455) | 評論 (0)編輯 收藏

          mongo phpadmin客戶端

          其實用mongo已經有些時候了,之所以算初探,是因為用的不深入,主要就是當中nosql中的類k-v用的,用之取代了部分的tt,原因很簡單,mongo中的數據格式雖然是bson的,不過在我這個pythoner眼中,這不明明就是純天然的 dict么!好吧,我承認,就是這個原因讓我義無反顧地走上了mongoing之路(無論什么項目,用到存儲自然而然的想用mongo)。 
          mongo的優劣是在使用的過程中逐步體驗出來的,在這里就不評說了,想要評測的請直接google之 

          之前一直是直接在服務器端用pymongo或者mongo自帶的shell做數據查看修改之類的操作,突然發現這個實在不利于推廣,公司同事似乎本能的對這種nosql有穩定性上的懷疑。也好理解,看不到的,通常是不可信的(誰說的來著)。 

          鑒于大伙都習慣了phpadmin玩mysql的光榮傳統,如果mongo也有類似的東東,看起來也親切些,個人感覺對推廣也會有利些。 

          額,說了這么多,好像還沒有能進入到主題,好吧,說是初探,似乎有些標題黨了,其實就想推薦下這個東東:http://code.google.com/p/rock-php/wiki/rock_mongo_zh#安裝 

          不錯的mongodb phpadmin客戶端,還支持中文(我想這個還是蠻有利推廣的),所謂初探,只不過是使用這東東換了個視角來看看Mongodb,感覺的確有些不一樣。 

          不過,值得注意到是,裝這玩意之前,還得為php裝一個mongo的drive,不過不要緊,裝完這個之后,訪問時會直接給個裝drive的鏈接,還是蠻方便的。 

          額,我應該不算標題黨吧(至少不是純碎的標題黨。。 
          來自:http://iyuan.javaeye.com/blog/799515

          posted @ 2011-03-23 10:28 狼愛上貍 閱讀(981) | 評論 (0)編輯 收藏

          mongo常用操作

          shell#查詢
          查詢 name = "bruce" 的數據
          db.users.find({ name : "bruce" });

          條件操作符
          $gt : >
          $lt : <
          $gte: >=
          $lte: <=
          $ne : !=、<>
          $in : in
          $nin: not in
          $all: all
          $not: 反匹配(1.3.3及以上版本)

          查詢 name <> "bruce" and age >= 18 的數據
          db.users.find({name: {$ne: "bruce"}, age: {$gte: 18}});

          查詢 creation_date > '2010-01-01' and creation_date <= '2010-12-31' 的數據
          db.users.find({creation_date:{$gt:new Date(2010,0,1), $lte:new Date(2010,11,31)});

          查詢 age in (20,22,24,26) 的數據
          db.users.find({age: {$in: [20,22,24,26]}});

          查詢 age取模10等于0 的數據
          db.users.find('this.age % 10 == 0');
          或者
          db.users.find({age : {$mod : [10, 0]}});

          匹配所有
          db.users.find({favorite_number : {$all : [6, 8]}});
          可以查詢出{name: 'David', age: 26, favorite_number: [ 6, 8, 9 ] }
          可以不查詢出{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }

          查詢不匹配name=B*帶頭的記錄
          db.users.find({name: {$not: /^B.*/}});
          查詢 age取模10不等于0 的數據
          db.users.find({age : {$not: {$mod : [10, 0]}}});

          #返回部分字段
          選擇返回age和_id字段(_id字段總是會被返回)
          db.users.find({}, {age:1});
          db.users.find({}, {age:3});
          db.users.find({}, {age:true});
          db.users.find({ name : "bruce" }, {age:1});
          0為false, 非0為true

          選擇返回age、address和_id字段
          db.users.find({ name : "bruce" }, {age:1, address:1});

          排除返回age、address和_id字段
          db.users.find({}, {age:0, address:false});
          db.users.find({ name : "bruce" }, {age:0, address:false});

          數組元素個數判斷
          對于{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }記錄
          匹配db.users.find({favorite_number: {$size: 3}});
          不匹配db.users.find({favorite_number: {$size: 2}});

          $exists判斷字段是否存在
          查詢所有存在name字段的記錄
          db.users.find({name: {$exists: true}});
          查詢所有不存在phone字段的記錄
          db.users.find({phone: {$exists: false}});

          $type判斷字段類型
          查詢所有name字段是字符類型的
          db.users.find({name: {$type: 2}});
          查詢所有age字段是整型的
          db.users.find({age: {$type: 16}});

          對于字符字段,可以使用正則表達式
          查詢以字母b或者B帶頭的所有記錄
          db.users.find({name: /^b.*/i});

          $elemMatch(1.3.1及以上版本)
          為數組的字段中匹配其中某個元素

          Javascript查詢和$where查詢
          查詢 age > 18 的記錄,以下查詢都一樣
          db.users.find({age: {$gt: 18}});
          db.users.find({$where: "this.age > 18"});
          db.users.find("this.age > 18");
          f = function() {return this.age > 18} db.users.find(f);

          排序sort()
          以年齡升序asc
          db.users.find().sort({age: 1});
          以年齡降序desc
          db.users.find().sort({age: -1});

          限制返回記錄數量limit()
          返回5條記錄
          db.users.find().limit(5);
          返回3條記錄并打印信息
          db.users.find().limit(3).forEach(function(user) {print('my age is ' + user.age)});
          結果
          my age is 18
          my age is 19
          my age is 20

          限制返回記錄的開始點skip()
          從第3條記錄開始,返回5條記錄(limit 3, 5)
          db.users.find().skip(3).limit(5);

          查詢記錄條數count()
          db.users.find().count();
          db.users.find({age:18}).count();
          以下返回的不是5,而是user表中所有的記錄數量
          db.users.find().skip(10).limit(5).count();
          如果要返回限制之后的記錄數量,要使用count(true)或者count(非0)
          db.users.find().skip(10).limit(5).count(true);

          分組group()
          假設test表只有以下一條數據
          { domain: "www.mongodb.org"
          , invoked_at: {d:"2009-11-03", t:"17:14:05"}
          , response_time: 0.05
          , http_action: "GET /display/DOCS/Aggregation"
          }
          使用group統計test表11月份的數據count:count(*)、total_time:sum(response_time)、 avg_time:total_time/count;
          db.test.group(
             { cond: {"invoked_at.d": {$gt: "2009-11", $lt: "2009-12"}}
             , key: {http_action: true}
             , initial: {count: 0, total_time:0}
             , reduce: function(doc, out){ out.count++; out.total_time+=doc.response_time }
             , finalize: function(out){ out.avg_time = out.total_time / out.count }
             } );

          [
            {
              "http_action" : "GET /display/DOCS/Aggregation",
              "count" : 1,
              "total_time" : 0.05,
              "avg_time" : 0.05
            }
          ]

          來自: http://hi.baidu.com/asminfo/blog/item/20301e22dcfcce50ac34de7a.html

          posted @ 2011-03-23 10:26 狼愛上貍 閱讀(1077) | 評論 (0)編輯 收藏

          grails 升級到1.3.6的亂碼解決方法

          原先的grails是1.2.0,從這個版本之后,我試過1.2.1,1.2.2,1.3.0,1.3.1,但都因為程序在運行時會變成亂碼,而一直使用著1.2.0。

          我們的TOMCAT使用的是GBK編碼,GRAILS文本都是使用UTF-8編碼,所以,這是產生亂碼的根本原因。

          最近又有grails1.3.6,更新得很快,網上找了找,有解決方案了。http://www.groovyq.net/content/grails13%E5%8F%91%E5%B8%83

          在服務器上一試,果然能行。現記錄如下:

          重新設定System.out的編碼,將下面語句加入到_GrailsInit.groovy中,或者加入工程的BootStrap.groovy的init段即可
          System.out = new PrintStream(System.out, true,"GB2312");

           

          我使用的是第二種方法,在BootStrap.groovy的init段中加入以上語句。

          以前,有位高手也提到過,但他的原文是:

          “如果是println打印中文亂碼的話,那么就在初始化文件中增加
           System.out = new  PrintStream(System.out, true, "GBK") 
          就應該了,你測試一下吧, ”

          所以我一直以為是解決打印亂碼的。

          在此一并謝過。


          來自: http://hi.baidu.com/caihexi/blog/item/76d093a4cce0c6e59152ee15.html

          posted @ 2011-03-23 10:25 狼愛上貍 閱讀(398) | 評論 (0)編輯 收藏

          MongoDB的基本操作

          詳細請閱: 
          http://www.oschina.net/code/snippet_35115_2888

          posted @ 2011-03-23 10:24 狼愛上貍 閱讀(244) | 評論 (0)編輯 收藏

          MongoDB的自增長主鍵的實現

          詳細請閱: 
          http://www.oschina.net/code/snippet_35115_2915

          posted @ 2011-03-23 10:23 狼愛上貍 閱讀(778) | 評論 (0)編輯 收藏

          mongo的初體驗

          首先在mongo官網下載Windows的版本 

          啟動服務:mongod.exe --port 12345 --dbpath=c:\mongodb\db 
          顯示一下信息: 
          Fri Dec 04 14:30:32 Mongo DB : starting : pid = 0 port = 12345 dbpath = c:\mongo 
          db\db master = 0 slave = 0  32-bit 

          ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data 

          **       see http://blog.mongodb.org/post/137788967/32-bit-limitations for more 

          Fri Dec 04 14:30:32 db version v1.1.4-, pdfile version 4.5 
          Fri Dec 04 14:30:32 git version: c67c2f7dd681152f1784c8e1c2119b979e65881d 
          Fri Dec 04 14:30:32 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI 
          B_VERSION=1_35 
          Fri Dec 04 14:30:32 waiting for connections on port 12345 


          啟動客戶端:mongo.exe localhost:12345 

          檢查是否正常:db.foo.save({a:1,b:9}) 
               db.foo.find({a:1}) 
          控制臺顯示:{ "_id" : ObjectId("4b18b5b56f40000000006cec"), "a" : 1, "b" : 9 } 


          添加數據:db.foo.save({a:1,b:9}) 

          查詢數據:db.foo.find({a:1})  //{a:1}是查詢條件,當為空時查詢所有 
            db.foo.findOne({a:1}) //顯示出一條數據 

          刪除數據:db.foo.remove({a:1}) //刪除a=1的數據 

          表的數據量:db.foo.find().count() 

          顯示數據指定的條數:db.foo.find().limit(n) 

          顯示庫名:db.foo.getDB() 

          獲取索引值:db.foo.getIndexes() 

          表的統計:db.foo.stats() 

          刪除表:db.foo.drop() 

          獲取不重復的列:db.foo.distinct( key ) - eg. db.foo.distinct( 'x' ) 

          忽略前面的幾行:db.other.find({a:2}).skip(2)//忽略a=2中的前面2行 

          方法幫助:db.foo.help() 


          HELP 
                  show dbs                     show database names 
                  show collections             show collections in current database 
                  show users                   show users in current database 
                  show profile                 show most recent system.profile entries with time >= 1ms 
                  use <db name>                set curent database to <db name> 
                  db.help()                    help on DB methods 
                  db.foo.help()                help on collection methods 
                  db.foo.find()                list objects in collection foo 
                  db.foo.find( { a : 1 } )     list objects in foo where a == 1 
                  it                           result of the last line evaluated; use to further iterate 


          DB methods: 
                  db.addUser(username, password) 
                  db.auth(username, password) 
                  db.cloneDatabase(fromhost) 
                  db.commandHelp(name) returns the help for the command 
                  db.copyDatabase(fromdb, todb, fromhost) 
                  db.createCollection(name, { size : ..., capped : ..., max : ... } ) 
                  db.currentOp() displays the current operation in the db 
                  db.dropDatabase() 
                  db.eval(func, args) run code server-side 
                  db.getCollection(cname) same as db['cname'] or db.cname 
                  db.getCollectionNames() 
                  db.getLastError() - just returns the err msg string 
                  db.getLastErrorObj() - return full status object 
                  db.getMongo() get the server connection object 
                  db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair 
                  db.getName() 
                  db.getPrevError() 
                  db.getProfilingLevel() 
                  db.getReplicationInfo() 
                  db.getSisterDB(name) get the db at the same server as this onew 
                  db.killOp() kills the current operation in the db 
                  db.printCollectionStats() 
                  db.printReplicationInfo() 
                  db.printSlaveReplicationInfo() 
                  db.printShardingStatus() 
                  db.removeUser(username) 
                  db.repairDatabase() 
                  db.resetError() 
                  db.runCommand(cmdObj) run a database command.  if cmdObj is a string, turns it into { cmdObj : 1 } 
                  db.setProfilingLevel(level) 0=off 1=slow 2=all 
                  db.shutdownServer() 
                  db.version() current version of the server 

          DBCollection help 
                  db.foo.count() 
                  db.foo.dataSize() 
                  db.foo.distinct( key ) - eg. db.foo.distinct( 'x' ) 
                  db.foo.drop() drop the collection 
                  db.foo.dropIndex(name) 
                  db.foo.dropIndexes() 
                  db.foo.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups 
                  db.foo.find( [query] , [fields]) - first parameter is an optional queryfilter. second parameter is optional set of fields to return.  e.g. db.foo.find( { x : 77 } , { name : 1 , x : 1 } ) 
                  db.foo.find(...).count() 
                  db.foo.find(...).limit(n) 
                  db.foo.find(...).skip(n) 
                  db.foo.find(...).sort(...) 
                  db.foo.findOne([query]) 
                  db.foo.getDB() get DB object associated with collection 
                  db.foo.getIndexes() 
                  db.foo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } ) 
                  db.foo.mapReduce( mapFunction , reduceFunction , <optional params> ) 
                  db.foo.remove(query) 
                  db.foo.renameCollection( newName ) renames the collection 
                  db.foo.save(obj) 
                  db.foo.stats() 
                  db.foo.storageSize() - includes free space allocated to this collection 
                  db.foo.totalIndexSize() - size in bytes of all the indexes 
                  db.foo.totalSize() - storage allocated for all data and indexes 
                  db.foo.update(query, object[, upsert_bool]) 
                  db.foo.validate() - SLOW 
                  db.foo.getShardVersion() - only for use with shardin
          來自: http://canofy.javaeye.com/blog/540926

          posted @ 2011-03-23 10:22 狼愛上貍 閱讀(440) | 評論 (0)編輯 收藏

          僅列出標題
          共38頁: First 上一頁 13 14 15 16 17 18 19 20 21 下一頁 Last 
          主站蜘蛛池模板: 育儿| 云南省| 建湖县| 六盘水市| 都安| 连平县| 建昌县| 景德镇市| 临江市| 宁阳县| 施秉县| 定边县| 理塘县| 阿克苏市| 屏东市| 德令哈市| 调兵山市| 黄骅市| 巴楚县| 娱乐| 合作市| 甘孜| 邓州市| 金华市| 古交市| 忻城县| 醴陵市| 阿尔山市| 盈江县| 昔阳县| 贵港市| 巴马| 沽源县| 襄樊市| 阿合奇县| 芜湖县| 洪泽县| 九江市| 阜宁县| 威海市| 屏南县|