MongoDB如何儲存資料

2021-06-28 11:25:46 字數 2321 閱讀 3235

看來最近是和mongodb的記憶體管理幹上了,要徹底搞清楚其原理。

下圖展示了資料庫是如何跟底層系統打交道的。

當建立資料庫時(其實mongodb沒有顯式建立資料庫的方法,在向資料庫中的集合寫入資料時會自動建立該資料庫),mongodb會在磁碟上分配一組資料檔案,所有集合,索引和資料庫的其他元資料都儲存在這些檔案裡。資料檔案被放在啟動時指定的dbpath裡,預設放入/data/db下面。典型的乙個檔案組織結構如下:

$ 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

,

"ok" : 1

}

使用db.accesslog.stats()確認某個集合的使用量

,

"ok" : 1

}

MongoDB如何儲存資料

原文 下圖展示了資料庫是如何跟底層系統打交道的。當建立資料庫時 其實mongodb沒有顯式建立資料庫的方法,在向資料庫中的集合寫入資料時會自動建立該資料庫 mongodb會在磁碟上分配一組資料檔案,所有集合,索引和資料庫的其他元資料都儲存在這些檔案裡。資料檔案被放在啟動時指定的dbpath裡,預設放...

MongoDB之資料儲存結構

1 mysql的資料儲存結構 mysql的每個資料庫都對應存放在乙個與資料庫同名的資料夾中,mysql資料庫檔案包括mysql所建資料庫檔案和mysql所用儲存引擎建立的資料庫檔案。mysql如果使用myisam儲存引擎,資料庫檔案型別就包括.frm myd myi mysql如果使用innodb儲...

scrapy儲存資料到mongodb

修改配置檔案settings.py新增 item pipelines mongo uri mongodb localhost 27017 mongo db qqnews 修改pipelines.py新增 class qqnewsmongopipeline object collection mili...