1
그래서 나는 내 응용 프로그램에 대해 다음과 레이아웃을했다 :캐스트 몽구스 문서
UserSchema는 (사용자에 대한 판별())
var UserSchema = new mongoose.Schema({ firstName: String, lastName: String, email: String, username: String, password: String }, options); UserSchema.plugin(passportLocalMongoose); module.exports = mongoose.model("User", UserSchema);
StudentSchema (사용자 이름 및 암호를 포함) 추가 필드가있는 경우
var StudentSchema = new mongoose.Schema({ indexNumber: String, courses: [{ id: { type: mongoose.Schema.Types.ObjectId, ref: "Course" }, entryDate: { type: Date, default: Date.now } }] }, options); module.exports = User.discriminator("Student", StudentSchema);
TeacherSchema (discriminator() o User.register에 내가 여권 로컬 전략을 사용하고 추가 필드
var TeacherSchema = new mongoose.Schema({ degree: String, courses: [{ type: mongoose.Schema.Types.ObjectId, ref: "Course" }] }, options); module.exports = User.discriminator("Teacher", TeacherSchema);
와 N 사용자)().
router.post("/register", function(req,res) {
var newUser = new User({
firstName: req.body.firstName,
lastName: req.body.lastName,
email: req.body.email,
username: req.body.username
});
User.register(newUser, req.body.password, function(err, user) {
if(err) throw err;
passport.authenticate("local")(req, res, function() {
req.flash("success", "Welcome " + user.username + ".");
res.redirect("/");
});
});
});
지금이 모든 것이 같은 모음 아래 사용자 내가 사용자 등록 후, 학생 또는 교사에 그를 "촉진"않기 때문에 내가 가지고 어떻게
(때문에 판별 기의) DB에서 그 객체의 추가 필드?