Get Started. It's Free
or sign up with your email address
MongoDB by Mind Map: MongoDB

1. 程式

1.1. connection

1.1.1. 設定

1.1.1.1. 如果有做 RS 或多台 server 需要在呼叫 conneciton 的寫入 server 連線資訊

1.1.2. Pooling

1.1.2.1. 新版好像拿掉了

1.2. Read

1.2.1. Read Preferences

1.2.1.1. 有做 RS 要注意

1.2.1.1.1. PRIMARY

1.2.1.1.2. PRIMARY_PREFERRED

1.2.1.1.3. SECONDARY

1.2.1.1.4. SECONDARY_PREFERRED

1.2.1.1.5. NEAREST

1.2.2. index 預設是學習機制,所以 query 不一定會使用到 index (學會就會一直用),可以使用 hint 強制使用建立的索引

1.3. Write

1.3.1. Write Concerns

1.3.1.1. Unacknowledged {w:0}

1.3.1.1.1. 寫入時,不等待 server 回應

1.3.1.2. Acknowledged {w:1}

1.3.1.2.1. 寫入時,會等待 server 回應,僅等待到寫入 memory

1.3.1.3. Journaled {w:1, j:true}

1.3.1.3.1. 寫入時,會等待 server 回應,除寫入 memory 也等到寫入 Journal log 用於確保 memory 的資料能寫入 disk

1.3.1.4. Replica Acknowledged {w: n}

1.3.1.4.1. n=2~n, n 表示等 n-1 台 second 寫入完成

1.3.1.4.2. 寫入時,等待 server 回應,n=2 表示除 primary server 需等待一台 secondary 寫入完成後,server 才會回應

1.3.2. update

1.3.2.1. Upsert = true

1.3.2.1.1. 如果 update 的資料不在時,會新增一筆資料

2. DB 本身

2.1. 資料結構設定

2.1.1. document base

2.1.1.1. 儘量不要用在多個 collection 有資料關係查詢上

2.2. index

2.2.1. Page Faults

2.2.1.1. 提升 page hit

2.2.1.1.1. 建立 index

2.2.1.1.2. 移除用不到的 Index

2.2.1.1.3. 提升 memory

2.2.2. 使用 explain 可以解釋查詢是否使用到 index

2.2.3. Index type

2.2.3.1. Default _id

2.2.3.1.1. 預設為 _id 建 index

2.2.3.2. Single Field

2.2.3.2.1. 單一欄位 index

2.2.3.3. Compound Index

2.2.3.3.1. 多欄位 index

2.2.3.4. Multikey Index

2.2.3.4.1. 可以針對 array 的值做 index

2.2.3.5. 這幾個沒玩過

2.2.3.5.1. Geospatial Index

2.2.3.5.2. Text Indexes

2.2.3.5.3. Hashed Indexes

2.2.4. Index Properties

2.2.4.1. Unique Indexes

2.2.4.1.1. 是否唯一值

2.2.4.2. Sparse Indexes

2.2.4.2.1. 該資料如果沒有該欄位,會被勿略,不建 index

2.2.4.3. TTL Indexes

2.2.4.3.1. 可以針對 timeout 的資料,自動 remove 的 index,可以解決在大資料量下 remove cost 很大的問題

2.3. 版本

2.3.1. v 2.8 以前地雷

2.3.1.1. Database Level Lock

2.3.1.1.1. 一個 database 建一個 collection

2.3.2. v 3.0

2.3.2.1. 使用 WiredTiger Storage Engine

2.3.2.1.1. 實現 Document Level Locking

2.4. multi read

2.4.1. Sharding

2.4.1.1. Replication

2.4.2. Replication

2.5. other

2.5.1. pretty

2.5.1.1. 輸出資料的好閱讀模式