Advertisement
Guest User

Untitled

a guest
Apr 4th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import mongoose from 'mongoose';
  2.  
  3. let schema = new mongoose.Schema({
  4. email: { type: String, required: true, unique: true },
  5. password: { type: String, required: true }
  6. });
  7.  
  8. schema.statics.findOrCreate = async (conditions, opt_attr) => {
  9. let document = await User.findOne(conditions);
  10.  
  11. return document || await new User({ ...conditions, ...opt_attr }).save();
  12. }
  13.  
  14. const User = mongoose.model('User', schema);
  15. export default User;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement