0

I'm trying to put a forum-like structure in a MongoDB 4.0 database, which consists of multiple threads under a same "topic", each thread consists of a bunch of posts. So usually there are no limits on the numbers of the threads and posts. And I want to try fully utilizing the benefits of NoSQL features, grabbing a list of posts under any speicified thread at one time without having to scan and look up for the identical "thread_id" and "post_id" in a RDBMS table in the traditional way, so in my mind I want to put all the threads as collections in a database, as the thread_id as the code-generated collection names, and put all the posts of a thread as normal documents under that collection, so the way to access a post may look like:

forum_db【database name】.thread_id【collection name】.post_id【document ID】

But my concern is, despite of the obscure phrase saying at https://docs.mongodb.com/manual/reference/limits/#data,

 Number of Collections in a Database

Changed in version 3.0.

For the MMAPv1 storage engine, the maximum number of collections in a database is a function of the size of the namespace file and the number of indexes of collections in the database.

The WiredTiger storage engine is not subject to this limitation.</pre>

Is it safe to do it in this way in terms of performance and scalability? Can we safely take it that there is no limit on the number of collections in a WiredTiger database (MongoDB 4.0+) today as there is pratically no limit on the number of documents in a collection? Many thanks in advance.

1 Answers1

0

To calculate how many collections one can store in a MongoDB database, you need to figure out the number of indexes in each collection.

WiredTiger engine keeps an open file handler for each used collection (and its indexes). A large number of open file handlers can cause extremely long checkpoints operations.

Furthermore, each of the handles will take about ~22KB memory outside the WT cache; this means that just for keeping the files open, mongod process will need ~NUM_OF_FILE_HANDLES * 22KB of RAM.

High memory swapping will lead to a decrease in performance.

As you probably understand from the above, different hardware (RAM size & Disk speed) will behave differently.

From my point of view, you first need to understand the behavior of your application then calculate the required hardware for your MongoDB database server.

Maxim Kirilov
  • 2,639
  • 24
  • 49