I am trying to get my users roles to update in the comments model. after hours os googling I am turning to StackOverflow to help me.I have an admin tool that where I can edit each users role, but it does not effect the users role data in the comments. Posted below are the user model, and the comments model.
var mongoose = require("mongoose");
var commentSchema = new mongoose.Schema({
text: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String,
isAdmin: { type: Boolean, default: false },
isOwner: { type: Boolean, default: false },
isCamper: { type: Boolean, default: false },
},
time: String
});
module.exports = mongoose.model("Comment", commentSchema);
user model
const mongoose = require("mongoose"),
passportLocalMongoose = require("passport-local-mongoose"),
UserSchema = new mongoose.Schema({
email: { type: String, unique: true, required: true },
username: { type: String, unique: true, required: true },
password: String,
isAdmin: { type: Boolean, default: false },
isOwner: { type: Boolean, default: false },
isCamper: { type: Boolean, default: false },
resetPasswordToken: String,
resetPasswordExpires: Date,
comments: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}]
});
UserSchema.plugin(passportLocalMongoose);
module.exports = mongoose.model("User", UserSchema);