<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## 索引 ### 索引限制 1. 讀操作的集合建議不使用索引 2. 索引存放內存,所以限制超過內存,超過將刪除部門索引 #### 查詢失效情況 * 正則表達式及非操作符,如 $nin, $not, 等。 * 算術運算符,如 $mod, 等。 * $where 子句 #### 最大范圍 * 集合中索引不能超過64個 * 索引名的長度不能超過128個字符 * 一個復合索引最多可以有31個字段 ### 索引類型 |Parameter| Type| Description| |---|---|---| |background| Boolean| 非阻塞建立索引 默認值為false。| |unique| Boolean| 建立的索引是否唯一。默認值為false.| |name| string| 索引的名稱。默認根據規則生成| |expireAfterSeconds| integer| 設定TTL設定,設定文檔的生存時間(秒)。| #### expireAfterSeconds 設置過期時間 1. 可指定多少秒后過期 ``` db.log_events.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } ) db.log_events.insert( { "createdAt": new Date(), "logEvent": 2, "logMessage": "Success!" } ) ``` 2. 指定某時間點過期 expireAfterSeconds必須設置為0 ``` db.log_events.createIndex( { "expireAt": 1 }, { expireAfterSeconds: 0 } ) db.log_events.insert( { "expireAt": new Date('July 22, 2013 14:00:00'), "logEvent": 2, "logMessage": "Success!" }) ``` ### 索引解析 ``` db.users.find({gender:"M"},{user_name:1,_id:0}).explain() ``` 結果 ``` { "cursor" : "BtreeCursor gender_1_user_name_1", "isMultiKey" : false, "n" : 1, "nscannedObjects" : 0, "nscanned" : 1, "nscannedObjectsAllPlans" : 0, "nscannedAllPlans" : 1, "scanAndOrder" : false, "indexOnly" : true, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "gender" : [ [ "M", "M" ] ], "user_name" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] } } indexOnly 字段為 true ,表示我們使用了索引。 cursor 因為這個查詢使用了索引,MongoDB 中索引存儲在B樹結構中,所以這是也使用了 BtreeCursor 類型的游標。如果沒有使用索引,游標的類型是 BasicCursor。這個鍵還會給出你所使用的索引的名稱,你通過這個名稱可以查看當前數據庫下的system.indexes集合(系統自動創建,由于存儲索引信息,這個稍微會提到)來得到索引的詳細信息。 n 當前查詢返回的文檔數量。 nscanned/nscannedObjects 表明當前這次查詢一共掃描了集合中多少個文檔,我們的目的是,讓這個數值和返回文檔的數量越接近越好。 millis 當前查詢所需時間,毫秒數。 indexBounds 當前查詢具體使用的索引。 ``` ### 創建索引 ``` db.users.ensureIndex({"tags":1}) ``` 查看索引是否生效 ``` db.users.find({tags:"cricket"}).explain() ``` 顯示 `"cursor" : "BtreeCursor tags_1" `說明生效 #### 索引子文檔字段 ``` db.users.ensureIndex({"address.city":1,"address.state":1,"address.pincode":1}) ``` 檢查是否生效 ``` db.users.find({"address.city":"Los Angeles"}).explain() ``` ### 使用 hint() 強制使用索引 ``` db.users.find({gender:"M"}}).hint({gender:1,user_name:1}) ``` ## 全文索引 ### 開啟全文索引 2.6 版本以后是默認開啟全文檢索的 如果是之前的版本 ``` >db.adminCommand({setParameter:true,textSearchEnabled:true}) ``` ### 查詢全文索引 ``` db.posts.find({$text:{$search:"runoob"}}) ``` ### 刪除全文索引 ``` //查詢索引名 db.posts.getIndexes() //刪除索引名 db.posts.dropIndex("post_text_text") ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看