我正在尝试让我的用户角色在评论模型中更新。在经过数小时的谷歌搜索之后,我将寻求StackOverflow的帮助。我有一个管理工具,可以在其中编辑每个用户角色,但不会影响注释中的用户角色数据。下面发布的是用户模型和评论模型。
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);
用户模型
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);