Schema design approach

Hi! I’m building a blog like app with mongoDB storage where many users can post many articles. Which is the best approach? 1. To have one collection of user documents in which I include the articles array. Or 2. have two collections, users and articles. In the articles collection I’ll store all of the users articles. What I’m thinking: If a user have only two articles, it is ok to search through 100k articles. On the other hand if a user have many articles and a single document have a max size of 16Mb and is not enough space?

Hi Marius,

You are looking at One-to-Many data relationship between the user and articles entities. You can model this as a single collection or two collections - this totally depends upon your use case. The most common questions you have to ask (yourself, in this case) are - what is the application, how many users and articles per user (maximum), the size of documents, the kind of queries (CRUD operations in general, and the most important queries), what functions are there in the application, etc.

There are some guidelines in the following documentation on modeling this data relationship:

1 Like