Mongodb - Large Collections of Documents

Asked

Viewed 474 times

2

I’m developing a website where users can vote for or against places they know about. To do this I could create a collection called "votes" relating the site to the user and whether it was for or against, the problem is that this can generate a huge collection of documents, another solution would be for the user document to have an array with its votes so I would separate the collection of votes in users. What is the best approach to this performance situation

  • 1

    Wouldn’t it be better to record the votes in the document? Usually votes are displayed when displaying the location, that is, when displaying a location, if you save votes to users, you will have to scroll through each user to find the local votes.

  • Dude, I don’t know how much information you will record in each document, but the user can have N votes and that means the document can grow without control. This is bad because the document is limited to 16MB.

  • In terms of data access, it would be best to have a new collection called votes, so both users and the location could search for their votes effortlessly. My concern is with Collection size, what will be the maximum recommended size for a Collection? @Filipemoraes

1 answer

2


In particular, I believe that the best solution would be to "denormalize".

Leave two fields in the document of the place (one with the amount of positive votes, and the other with negative votes) and another Voting Center, summarizing place + vote + person.

In this way, if you need to list the places, you already have the information of votes per place (without having to add other places), and you have the information itself in the Polling Place, if you need to search for specifics per person.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.