Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. 'use strict';
  2. var crypto = require('crypto');
  3. var mongoose = require('mongoose'),
  4. extend = require('mongoose-schema-extend');
  5. var Schema = mongoose.Schema;
  6.  
  7. /*
  8.  
  9. Example of how to use mongoose-schema extend
  10. User documents and AuthUser documents will be in the same collection/table
  11. but if we query for users --- User.find({}) --- this will return only users whose
  12. discriminatorKey (type) is User
  13.  
  14. so user documents will have a `type` field that points to the string "User"
  15. because we name the model "User"
  16.  
  17. u.type === 'User'
  18.  
  19. same for authUsers --- they will have a `type` field that points to "AuthUser"
  20.  
  21. in this case, `User` is the base class
  22. */
  23.  
  24. var User = new Schema({
  25. firstName: {type: String, required: true},
  26. lastName: {type: String, required: true},
  27. email: {type: String, required: true, unique: true},
  28. address: {
  29. street: {type: String},
  30. city: {type: String},
  31. state: {type: String},
  32. zip: {type: String}
  33. }
  34. }, {collection: 'users', discriminatorKey: 'type'});
  35.  
  36. var authUser = User.extend({
  37. password: String,
  38. salt: String,
  39. roles: [String],
  40. twitter: {id: String, username: String, token: String, tokenSecret: String},
  41. facebook: {id: String},
  42. google: {id: String},
  43. needPwReset: {type: Boolean, defeault: false},
  44. inactive: {type: Boolean, default: false}
  45. });
  46.  
  47.  
  48.  
  49. mongoose.model('User', User);
  50. mongoose.model('AuthUser', authUser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement