- MongoDB Administrator’s Guide
- Cyrus Dasadia
- 379字
- 2021-07-02 15:47:45
How it works...
We start by running a mongod instance with no special parameters except for --dbpath. In step 2, we create a new database mydb and insert a document in the collection mycol, using the mongo shell. By doing this, the data files for this new db are created and can be seen by inspecting the directory structure of our main database path /data/db. In that, among other files, you can see that database files begin with collection-<number> and its relevant index file begins with index-<number>. As we guessed, all databases and their relevant files are within the same directory as our db path.
If you are curious and wish to find the correlation between the files and the db, then run the following commands in mongo shell:
> use mydb
> var curiosity = db.mycol.stats()
> curiosity['wiredTiger']['uri']
statistics:table:collection-5-626293768203557661
The last part of this string that is, collection-5-626293768203557661 corresponds to the file in our /data/db path.
Moving on, in steps 4 and step 5, we stop the previous mongod instance, create a new path for our data files and start a new mongod instance but this time with the --directoryperdb parameter. As before, in step 6 we insert some random data in the mycol collection of a new database called mydb. In step 7, we look at the directory listing of our data path and we can see that there is a subdirectory in the data path which, as you guessed, matches our database name mydb. If you look inside this directory that is, /data/newdb/mydb, you should see a collection and an index file.
So one might ask, why go through all this trouble for having separate directories for databases? Well, in certain application scenarios, if your database workloads are significantly high, you should consider storing the database on a separate disk/volume. Ideally, this should be a physically separate disk or a RAID volume created using separate physical disks. This ensures the separation of disk I/O from other operations including MongoDB journals. Additionally, this also helps you separate your fault domains. One thing you should keep in mind is that journals are stored separately, that is, outside the database's directory. So, using separate disks for databases allows the journals to not content for same disk I/O path.
- C/C++常用算法手冊(第3版)
- Learning Neo4j 3.x(Second Edition)
- 正則表達式經典實例(第2版)
- 深入淺出RxJS
- Python算法從菜鳥到達人
- Advanced Oracle PL/SQL Developer's Guide(Second Edition)
- 大模型RAG實戰(zhàn):RAG原理、應用與系統(tǒng)構建
- Extending Puppet(Second Edition)
- PHP+MySQL+Dreamweaver動態(tài)網站開發(fā)從入門到精通(第3版)
- Learning Concurrency in Kotlin
- 現代C++編程實戰(zhàn):132個核心技巧示例(原書第2版)
- Scala for Machine Learning(Second Edition)
- R語言數據可視化:科技圖表繪制
- Getting Started with React VR
- 微信小程序開發(fā)邊做邊學(微課視頻版)