Ask coding questions

← Back to all posts
What's the amount of documents in mongodb in which it starts to get slow?

In my last project Drinks Cabin, the website got way to slow because of too many documents in a collection in the mongodb database. Now I'm thinking of adding shards so there will be a certain amount of documents (user profiles) in each collection so it's easier. I'll add the username and its shard number in json (because I feel like it's going to be faster because it's a dictionary).
How many documents should I have in each shard so it isn't slow and there aren't too many shards? (In my last project there were 1609 documents)


No, you should not worry about performance, you should worry about organizing your documents.

If you have a lot of data that gets retrieved many times, consider making another collection with that data.
If you have data that gets retrieved rarely, then make sure to separate that from the collection 'chache'


If I loop thru a collection looking for a special key which only a few documents have, will it only loop thru those documents? @Coder100


So with mongodb, you shouldn't really worry about the number of documents total unless you're serving all of those documents. If you're serving lots of documents, it might make sense to do pagination.


but I loop through all of the documents sometimes @RoBlockHead


It really depends on what the file is. Ex: How large is the file?





Maybe use sql instead? That might be faster.


But I'm used to mongodb and the sql can be shown in my repl, I don't want people to fork it and see all the data, especially that I might be saving emails @IntellectualGuy