Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
How to correctly create a reference between two models in mongodb using Mongoose?

The issue is that I have two Mongoose schema models - user and movie. A single movie will not be accessible for each user, so in the movie model I made a reference to the user as an array. On the frontend the user will have available a list of all his films. Additionally, I would like each user among the videos available to them to have the option to like a particular video.

I tried to add another reference in the user model with an array of favorite movies, but this solution seems too complicated when I try to implement this on the frontend. Do any of you have an idea how to do it better? I also thought to add a Boolean value by adding an isFavorite field to the movie model, but then all users would see that movie as favorite.

Movie Schema:

const movieSchema = mongoose.Schema(
  {
    user: [
      {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
        ref: 'User',
      },
    ],
    name: {
      type: String,
      required: true,
    },
    url: {
      type: String,
    },
}

User Schema:

const userSchema = mongoose.Schema(
  {
    name: {
      type: String,
      required: true,
    },
    password: {
      type: String,
      required: true,
    },
    email: {
      type: String,
      required: true,
      unique: true,
    },
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda