Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Collection set up MongoDB scaling

I'm trying to conceptualise the best way to scale a MongoDB Database.

For example, say you want to create a site selling houses in different states using a MongoDB on the backend. For future scalability and site performance, would it be best practice to have multiple collections for every state or list everything under USA and then search or find the state within the collection?

**Collection - Texas**

{"_id":{"$oid":"xxxxxxxxxxxxx"},"name":"Modern loft","state":"Texas"}
{"_id":{"$oid":"xxxxxxxxxxxxx"},"name":"Vacant Plot","state":"Texas"}
x 1000 entries

**Collection - USA**

{"_id":{"$oid":"xxxxxxxxxxxxx"},"name":"Family Home","state":"Texas"}
{"_id":{"$oid":"xxxxxxxxxxxxx"},"name":"Beach House","state":"California"}
x 1000 entries
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It all depends on how would you search and present the data...

From performance perspective even it will be best to split the data in database per state and collections to represent the city , but this mean additional logic in your app to support the model and the logic to fetch some global details from all states/cities will become abit more complex.

If you have everything in single collection and you choose good indexes there will be no issues , at some point in time when the database grow you will just need to split the collection in more shards , but the logic to deal with the database will stay simple since you will have everything in single place. ( this is where your database of choice-mongodb can be of help since the sharding mechanism is build in and very easy to configure )

So to me seems splitting the data to states as good compromise since there is no need the people from Oregon to query all the USA data to find few houses in some small village in Oregon when they can search only the collection in Oregon , but at the same time if you shard the collection and you have good sharding index that include the state , the query will go just to the shard where Oregon data is located ... , with the sharding there is other trick for example if you search houses with swimming pool , but you dont include the state in the filter ( if it is sharding key ) the query will do scatter-gather to all shards to find those hauses ...

I hope that answer your question ...

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda