Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mongoose from 'mongoose';
- let schema = new mongoose.Schema({
- email: { type: String, required: true, unique: true },
- password: { type: String, required: true }
- });
- schema.statics.findOrCreate = async (conditions, opt_attr) => {
- let document = await User.findOne(conditions);
- return document || await new User({ ...conditions, ...opt_attr }).save();
- }
- const User = mongoose.model('User', schema);
- export default User;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement