乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      創(chuàng)建索引

       CevenCheng 2011-07-11

      索引能提高檢索數(shù)據(jù)的速度,你可以想像成在MySQL中創(chuàng)建索引一樣,同樣索引也是用B-Tree也實現(xiàn)的。
      創(chuàng)建schedule的collection:
      // 實例化Mongo對象,連接27017端口
      Mongo mongo = new Mongo("localhost", 27017);
      // 連接名為yourdb的數(shù)據(jù)庫,假如數(shù)據(jù)庫不存在的話,mongodb會自動建立
      DB db = mongo.getDB("test");
      //得到要查詢數(shù)據(jù)的 Collction, 如果沒有就創(chuàng)建
      DBCollection coll = db.getCollection("schedule");

      Getting a List of Indexes on a Collection

      List<DBObject> indexList = coll.getIndexInfo();  
      for (DBObject o : indexList) {  
              System.out.println("index ---------" + o);  
      }

      Creating An Index

      創(chuàng)建索引

      MongoDB supports indexes, and they are very easy to add on a collection. To create an index, you just specify the field that should be indexed, and specify if you want the index to be ascending (1) or descending (-1). The following creates an ascending index on the "i" field :

      MongoDB支持索引,并且很容易添加。只需要指定索引的字段和排序(升序1,降序-1)。下面是創(chuàng)建i降序索引的例子:

      1coll.createIndex(new BasicDBObject("i"1));  // create index on "i", ascending

       

      Getting a List of Indexes on a Collection

      查詢collection全部索引

      You can get a list of the indexes on a collection :

       

      1List<DBObject> list = coll.getIndexInfo();
      2 
      3 
      4 
      5for (DBObject o : list) {
      6 
      7    System.out.println(o);
      8 
      9}
       

      and you should see something like

      打印如下

      1"name" "i_1" "ns" "mydb.testCollection" "key" : { "i" 1} }


        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多