I am currently working on linking specific fields from the User model to the Card schema using the username as a reference point. Let me provide an example using my Card schema:
const CardSchema = new mongoose.Schema({
text: {
type: String,
},
username: {
type: String,
ref: 'User',
required: true
},
userSticker: {
I need to extract this information from the user model based on either the username or user ID.
}
Now, let's take a look at how the user model is structured:
const UserSchema = new mongoose.Schema({
username: {
type: String,
},
userSticker: {
type: String,
}
Essentially, what I am trying to achieve is to always have the same userSticker value in the Card schema as the corresponding user in the User model. Simply adding it upon card creation won't suffice since the userSticker may change over time. Therefore, I am looking for a solution that will dynamically update the field in the Card schema whenever the associated user's userSticker changes - perhaps through some form of reference implementation.