Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose = require('mongoose');
- var uniqueValidator = require('mongoose-unique-validator');
- // schema representing user data
- var UserSchema = new mongoose.Schema(
- {
- username: {
- type: String,
- lowercase: true,
- unique: true,
- required: [true, "can't be blank"],
- match: [/^[a-zA-Z0-9]+$/, 'is invalid'],
- index: true,
- },
- email: {
- type: String,
- lowercase: true,
- unique: true,
- required: [true, "can't be blank"],
- match: [/\S+@\S+\.\S+/, 'is invalid'],
- index: true,
- },
- bio: String,
- image: String,
- hash: String,
- salt: String,
- },
- {timestamps: true}
- );
- UserSchema.plugin(uniqueValidator, {message: 'is already taken.'});
- // register the schema with mongoose as 'User'
- mongoose.model('User', UserSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement