時(shí)間:2024-03-26 14:42作者:下載吧人氣:40
前言
本文主要介紹了關(guān)于MongoDB存儲(chǔ)數(shù)據(jù)的相關(guān)內(nèi)容,分享出來(lái)供大家參考學(xué)習(xí),下面來(lái)一起看看詳細(xì)的介紹:
想要深入了解MongoDB如何存儲(chǔ)數(shù)據(jù)之前,有一個(gè)概念必須清楚,那就是Memeory-Mapped Files。
Memeory-Mapped Files
下圖展示了數(shù)據(jù)庫(kù)是如何跟底層系統(tǒng)打交道的。
MongoDB的存儲(chǔ)模型
數(shù)據(jù)文件與空間分配
當(dāng)創(chuàng)建數(shù)據(jù)庫(kù)時(shí)(其實(shí)MongoDB沒(méi)有顯式創(chuàng)建數(shù)據(jù)庫(kù)的方法,在向數(shù)據(jù)庫(kù)中的集合寫(xiě)入數(shù)據(jù)時(shí)會(huì)自動(dòng)創(chuàng)建該數(shù)據(jù)庫(kù)),MongoDB會(huì)在磁盤上分配一組數(shù)據(jù)文件,所有集合,索引和數(shù)據(jù)庫(kù)的其他元數(shù)據(jù)都保存在這些文件里。數(shù)據(jù)文件被放在啟動(dòng)時(shí)指定的dbpath里,默認(rèn)放入/data/db下面。典型的一個(gè)文件組織結(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.lock
drwxr-xr-x 2 root root 4096 11-13 18:39 journal
drwxr-xr-x 2 root root 4096 11-13 19:02 _tmp
網(wǎng)友評(píng)論