<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    狼愛上貍

    我胡漢三又回來了

    #

    mongo數(shù)據(jù)庫的下載與安裝(windows xp環(huán)境下)

    1.下載數(shù)據(jù)庫http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip

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

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

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

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

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


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

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

    win7 啟動 mongo 方案

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

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

    mongo 命令集

    首先在mongo官網(wǎng)下載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 } 


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

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

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

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

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

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

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

    表的統(tǒng)計: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 狼愛上貍 閱讀(2151) | 評論 (0)編輯 收藏

    mongo shell命令

    命令行

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

    特殊命令

    非JavaScript的輔助指令:

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

    基本的Shell Javascript操作

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

    查詢

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

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

    錯誤檢查

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

    管理命令

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

    打開額外連接

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

    其他

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

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

    mongo phpadmin客戶端

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

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

    鑒于大伙都習慣了phpadmin玩mysql的光榮傳統(tǒng),如果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 狼愛上貍 閱讀(979) | 評論 (0)編輯 收藏

    mongo常用操作

    shell#查詢
    查詢 name = "bruce" 的數(shù)據(jù)
    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 的數(shù)據(jù)
    db.users.find({name: {$ne: "bruce"}, age: {$gte: 18}});

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

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

    查詢 age取模10等于0 的數(shù)據(jù)
    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 的數(shù)據(jù)
    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});

    數(shù)組元素個數(shù)判斷
    對于{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及以上版本)
    為數(shù)組的字段中匹配其中某個元素

    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});

    限制返回記錄數(shù)量limit()
    返回5條記錄
    db.users.find().limit(5);
    返回3條記錄并打印信息
    db.users.find().limit(3).forEach(function(user) {print('my age is ' + user.age)});
    結(jié)果
    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);

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

    分組group()
    假設test表只有以下一條數(shù)據(jù)
    { 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統(tǒng)計test表11月份的數(shù)據(jù)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 狼愛上貍 閱讀(1074) | 評論 (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編碼,所以,這是產(chǎn)生亂碼的根本原因。

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

    在服務器上一試,果然能行。現(xiàn)記錄如下:

    重新設定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 狼愛上貍 閱讀(396) | 評論 (0)編輯 收藏

    MongoDB的基本操作

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

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

    MongoDB的自增長主鍵的實現(xiàn)

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

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

    mongo的初體驗

    首先在mongo官網(wǎng)下載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 } 


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

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

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

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

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

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

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

    表的統(tǒng)計: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 狼愛上貍 閱讀(438) | 評論 (0)編輯 收藏

    僅列出標題
    共38頁: First 上一頁 13 14 15 16 17 18 19 20 21 下一頁 Last 
    主站蜘蛛池模板: 免费不卡中文字幕在线| 中文字幕久精品免费视频| 亚洲日韩国产精品乱-久| 亚洲视频在线一区二区三区| 亚洲成色在线影院| 亚洲AV无码乱码在线观看富二代| 狠狠色伊人亚洲综合成人| 亚洲区小说区图片区QVOD| 国产精品亚洲片在线观看不卡| 亚洲综合熟女久久久30p| 亚洲精品无码乱码成人| 亚洲av永久无码精品漫画| 亚洲一级二级三级不卡| 中文字幕亚洲色图| 亚洲乱码日产精品BD在线观看| 亚洲一区二区三区久久| 亚洲人成未满十八禁网站| 亚洲精品无码aⅴ中文字幕蜜桃| 国产精品无码亚洲一区二区三区| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 搡女人免费免费视频观看| 水蜜桃视频在线观看免费播放高清 | 亚洲国产精品无码成人片久久| 久久91亚洲精品中文字幕| 亚洲精品美女久久久久9999| 亚洲一卡二卡三卡| 亚洲av中文无码乱人伦在线观看 | 亚洲国产成人精品无码区在线秒播| 亚洲剧场午夜在线观看| 亚洲爆乳大丰满无码专区| 日韩精品视频在线观看免费| 水蜜桃视频在线观看免费播放高清| 久久国产乱子伦免费精品| 最近的免费中文字幕视频| 啊灬啊灬别停啊灬用力啊免费看| 久久综合亚洲色HEZYO国产| 午夜亚洲AV日韩AV无码大全| 亚洲一区二区三区久久久久| 一级毛片大全免费播放| 日韩电影免费观看| 在线观看人成网站深夜免费|