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

179
Visualizações
Normalization and Denormalization MongoDB | Schema Question Follow System

I'm breaking my head over this:

The User on my WebApp can follow a Tag (Like a user can follow a subreddit), the followed Tag will be shown in the Homepage with a different color than the not followed one. If a User follows a Tag he will get Push-Notifications when a new Blog Post is published tagged with the Tag.

So I have to query for all the tags a given user follows.

And I have to query for all the user which follow a given tag.

A user can follow max 20 Tags. Since I have a Many to Many relation should i go with something like this (normalization)

const SubscribeToTagSchema = new Mongoose.Schema({
 user: {
  type: Schema.Types.ObjectId,
  ref: "User",
  required: true,
 },
 tag: {
  type: Schema.Types.ObjectId,
  ref: "Tag",
  required: true,
 },
});

or should I just save the data in both schema User and Tag?

const UserSchema = new Mongoose.Schema({
 tag: {
  type: Schema.Types.ObjectId,
  ref: "Tag",
  required: true,
 },
});

const TagSchema = new Mongoose.Schema({
 user: {
  type: Schema.Types.ObjectId,
  ref: "User",
  required: true,
 },
});
about 4 years ago · Juan Pablo Isaza
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