Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!