17 lines
490 B
JavaScript
17 lines
490 B
JavaScript
const mongoose = require("mongoose");
|
|
const Schema = mongoose.Schema;
|
|
|
|
const UserSchema = new Schema({
|
|
username: { type: String, required: true },
|
|
password: { type: String, required: true },
|
|
_id: { type: mongoose.ObjectId, required: true },
|
|
});
|
|
|
|
// Virtual for user URL
|
|
UserSchema.virtual("url").get(function () {
|
|
// We don't use an arrow function as we'll need the this object
|
|
return `/user/${this._id}`;
|
|
});
|
|
|
|
// Export model
|
|
module.exports = mongoose.model("User", UserSchema);
|