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

234
Visualizações
Single big collection for all products vs Separate collections for each Product category

I'm new to NoSQL and I'm trying to figure out the best way to model my database. I'll be using ArangoDB in the project but I think this question also stands if using MongoDB.

The database will store 12 categories of products. Each category is expected to hold hundreds or thousands of products. Products will also be added / removed constantly.

There will be a number of common fields across all products, but each category will also have unique fields / different restrictions to data.

Keep in mind that there are instances where I'd need to query all the categories at the same time, for example to search a product across all categories, and other instances where I'll only need to query one category.

Should I create one single collection "Product" and use a field to indicate the category, or create a seperate collection for each category?

I've read many questions related to this idea (1 collection vs many) but I haven't been able to reach a conclusion, other than "it dependes".

So my question is: In this specific use case which option would be most optimal, multiple collections vs single collection + sharding, in terms of performance and speed ?

Any help would be appreciated.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As you mentioned, you need to play with your data and use-case. You will have better picture.

Some decisions required as below.

  1. Decide the number of documents you will have in near future. If you will have 1m documents in an year, then try with at least 3m data

  2. Decide the number of indices required.

  3. Decide the number of writes, reads per second.

  4. Decide the size of documents per category.

  5. Decide the query pattern.

Some inputs based on the requirements

  1. If you have more writes with more indices, then single monolithic collection will be slower as multiple indices needs to be updated.

  2. As you have different set of fields per category, you could try with multiple collections. There is $unionWith to combine data from multiple collections. But do check the performance it purely depends on the above decisions. Note this open issue also.

  3. If you decide to go with monolithic collection, defer the sharding. Implement this once you found that queries are slower.

  4. If you have more writes on the same document, writes will be executed sequentially. It will slow down your read also.

  5. Think of reclaiming the disk space when more data is cleared from the collections. Multiple collections do good here.


  1. The point which forces me to suggest monolithic collections is that I'd need to query all the categories at the same time. You may need to add more categories, but combining all of them in single response would not be better in terms of performance.

  2. As you don't really have a join use case like in RDBMS, you can go with single monolithic collection from model point of view. I doubt you could have a join key.

If any of my points are incorrect, please let me know.

over 4 years ago · Santiago Trujillo Relatório

0

To SQL or to NoSQL?

I think that before you implement this in NoSQL, you should ask yourself why you are doing that. I quite like NoSQL but some data is definitely a better fit to that model than others.

The data you are describing is a classic case for a relational SQL DB. That's fine if it's a hobby project and you want to try NoSQL, but if this is for a production environment or client, you are likely making the situation more difficult for them.

Relational or non-relational?

You mention common fields across all products. If you wish to update these fields and have those updates reflected in all products, then you have relational data.

Background

It may be worth reading Sarah Mei 2013 article about this. Skip to the section "How MongoDB Stores Data" and read from there. Warning: the article is called "Why You Should Never Use MongoDB" and is (perhaps intentionally) somewhat biased against Mongo, so it's important to read this through the correct lens. The message you should get from this article is that MongoDB is not a good fit for every data type.

Two strategies for handling relational data in Mongo:

  1. every time you update one of these common fields, update every product's document with the new common field data. This is generally only ok if you have few updates or few documents, but not both.
  2. use references and do joins.
  • In Mongo, joins typically happen code-side (multiple db calls)
  • In Arango (and in other graph dbs, as well as some key-value stores), the joins happen db-side (single db call)

Decisions

These are important factors to consider when deciding which DB to use and how to model your data

I've used MongoDB, ArangoDB and Neo4j.

  • Mongo definitely has the best tooling and it's easy to find help, but I don't believe it's good fit in this case
  • Arango is quite pleasant to work with, but doesn't yet have the adoption that it deserves
  • I wouldn't recommend Neo4j to anyone looking for a NoSQL solution, as its nodes and relations only support flat properties (no nesting, so not real documents)
  • It may also be worth considering MariaDB or Postgres
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