-
-
Save adelowo/423335826024a85a88542b11ed9a1183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
const findOneOrCreate = require('mongoose-findoneorcreate'); | |
const bcrypt = require('mongoose-bcrypt'); | |
const timestamps = require('mongoose-timestamp'); | |
const UserSchema = new mongoose.Schema( | |
{ | |
username: { | |
type: String, | |
trim: true, | |
required: true, | |
}, | |
password: { | |
type: String, | |
required: true, | |
bcrypt: true, | |
}, | |
}, | |
{ | |
collection: 'users', | |
} | |
); | |
UserSchema.plugin(findOneOrCreate); | |
UserSchema.plugin(bcrypt); | |
UserSchema.plugin(timestamps); | |
UserSchema.index({ createdAt: 1, updatedAt: 1 }); | |
module.exports = mongoose.model('User', UserSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment