前言
本文主要介紹了關(guān)于MongoDB存儲數(shù)據(jù)的相關(guān)內(nèi)容,分享出來供大家參考學(xué)習(xí),下面來一起看看詳細(xì)的介紹:
想要深入了解MongoDB如何存儲數(shù)據(jù)之前,有一個概念必須清楚,那就是Memeory-Mapped Files。
Memeory-Mapped Files
下圖展示了數(shù)據(jù)庫是如何跟底層系統(tǒng)打交道的。
MongoDB的存儲模型
數(shù)據(jù)文件與空間分配
當(dāng)創(chuàng)建數(shù)據(jù)庫時(其實MongoDB沒有顯式創(chuàng)建數(shù)據(jù)庫的方法,在向數(shù)據(jù)庫中的集合寫入數(shù)據(jù)時會自動創(chuàng)建該數(shù)據(jù)庫),MongoDB會在磁盤上分配一組數(shù)據(jù)文件,所有集合,索引和數(shù)據(jù)庫的其他元數(shù)據(jù)都保存在這些文件里。數(shù)據(jù)文件被放在啟動時指定的dbpath里,默認(rèn)放入/data/db下面。典型的一個文件組織結(jié)構(gòu)如下:
$ cat /data/db$ ls -al-rw------- 1 root root 16777216 09-18 00:54 local.ns-rw------- 1 root root 67108864 09-18 00:54 local.0-rw------- 1 root root 2146435072 09-18 00:55 local.1-rw------- 1 root root 2146435072 09-18 00:56 local.2-rw------- 1 root root 2146435072 09-18 00:57 local.3-rw------- 1 root root 2146435072 09-18 00:58 local.4-rw------- 1 root root 2146435072 09-18 00:59 local.5-rw------- 1 root root 2146435072 09-18 01:01 local.6-rw------- 1 root root 2146435072 09-18 01:02 local.7-rw------- 1 root root 2146435072 09-18 01:03 local.8-rw------- 1 root root 2146435072 09-18 01:04 local.9-rw------- 1 root root 2146435072 09-18 01:05 local.10-rw------- 1 root root 16777216 09-18 01:06 test.ns-rw------- 1 root root 67108864 09-18 01:06 test.0-rw------- 1 root root 134217728 09-18 01:06 test.1-rw------- 1 root root 268435456 09-18 01:06 test.2-rw------- 1 root root 536870912 09-18 01:06 test.3-rw------- 1 root root 1073741824 09-18 01:07 test.4-rw------- 1 root root 2146435072 09-18 01:07 test.5-rw------- 1 root root 2146435072 09-18 01:09 test.6-rw------- 1 root root 2146435072 09-18 01:11 test.7-rw------- 1 root root 2146435072 09-18 01:13 test.8...-rwxr-xr-x 1 root root 6 09-18 13:54 mongod.lockdrwxr-xr-x 2 root root 4096 11-13 18:39 journaldrwxr-xr-x 2 root root 4096 11-13 19:02 _tmp