less than 1 minute read

One of the things that I wish I knew when I was starting out was that overthinking the Database design for extreme use cases is not a good idea.
I spent days trying to figure out how I should implement the database design for user chats, then after giving up when the complexity of the database got too crazy, did it the following way.

chat

There are 2 collections Chatroom and Chat. Each chatroom has 2 users, and the chats of the users are stored in multiple ‘Chat’ documents as buckets (Overkill I know). This way I can find all the chats of a user and load only the most recent 100 or so (The Max size of bucket) messages when asked.
I made a compound Indexes (User1, User2) and a simple Index(User2) to find and delete chats between users. (Might have to remove User2 index later if the size of the database increases too much)

On To the Test One…