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,
},
}