We have a social app where users can chat with each other and we’ve reached 350K messages!
We recently noticed that as the number of messages is growing, the find
operations are getting slower! I believe the issue here is that the Message
collection is not indexed.
That’s what I want to do now! I found this piece of code at the MongoDB docs:
db.comments.ensure_index(('discussion_id', 1))
This is my Message collection:
{
chatRoom: <Pointer>,
user: <Pointer>,
text: <String>,
isSeen: <Bool>
}
So I guess this is all I have to do:
db.Message.ensure_index(('chatRoom', 1))
Is that just it? Run this command and I’m all set? All existing and future messages will be indexed after that?