Skip to content

Instantly share code, notes, and snippets.

@adelowo
Created March 17, 2020 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adelowo/423335826024a85a88542b11ed9a1183 to your computer and use it in GitHub Desktop.
Save adelowo/423335826024a85a88542b11ed9a1183 to your computer and use it in GitHub Desktop.
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