Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var UserSchema = new mongoose.Schema({
- firstName: String,
- lastName: String,
- image: {
- type: String,
- default: "http://via.placeholder.com/250x200"
- },
- email: {
- type: String,
- required: [true, "Email missing."],
- unique: true
- },
- kind: {
- type: String,
- enum: ["Admin", "Teacher", "Student"],
- default: "Student"
- },
- isAdmin: {
- type: Boolean,
- default: false
- },
- isPromote: {
- type: Boolean,
- default: false
- },
- username: {
- type: String,
- required: [true, "Username missing."],
- unique: true
- },
- password: String
- }, options);
- UserSchema.plugin(passportLocalMongoose);
- module.exports = mongoose.model("User", UserSchema);
- var options = {discriminatorKey: 'kind'};
- var StudentSchema = new mongoose.Schema({
- indexNumber: String,
- }, options);
- module.exports = User.discriminator("Student", StudentSchema);
- var CourseSchema = new mongoose.Schema({
- teachers: [{
- type: mongoose.Schema.Types.ObjectId,
- ref: "Teacher"
- }],
- students: [{
- id: {
- type: mongoose.Schema.Types.ObjectId,
- ref: "Student"
- },
- entryDate: {
- type: Date,
- default: Date.now
- }
- }]
- Course.findById(req.params.id)
- .populate("students.id")
- .populate("teachers")
- .exec( function(err, foundCourse) {...}
- students: [ { _id: 59dbd1259df328279cd5d588, entryDate: 2017-10-12T22:29:48.297Z }, { _id: 59dc07088c6fd636188d87c5, entryDate: 2017-10-12T22:29:48.297Z } ], teachers: [ { _id: 59dbc34832b0041b44a7f648, isPromote: false, isAdmin: false, kind: 'Teacher', image: 'http://via.placeholder.com/250x200' } ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement