Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var crypto = require('crypto');
- var mongoose = require('mongoose'),
- extend = require('mongoose-schema-extend');
- var Schema = mongoose.Schema;
- /*
- Example of how to use mongoose-schema extend
- User documents and AuthUser documents will be in the same collection/table
- but if we query for users --- User.find({}) --- this will return only users whose
- discriminatorKey (type) is User
- so user documents will have a `type` field that points to the string "User"
- because we name the model "User"
- u.type === 'User'
- same for authUsers --- they will have a `type` field that points to "AuthUser"
- in this case, `User` is the base class
- */
- var User = new Schema({
- firstName: {type: String, required: true},
- lastName: {type: String, required: true},
- email: {type: String, required: true, unique: true},
- address: {
- street: {type: String},
- city: {type: String},
- state: {type: String},
- zip: {type: String}
- }
- }, {collection: 'users', discriminatorKey: 'type'});
- var authUser = User.extend({
- password: String,
- salt: String,
- roles: [String],
- twitter: {id: String, username: String, token: String, tokenSecret: String},
- facebook: {id: String},
- google: {id: String},
- needPwReset: {type: Boolean, defeault: false},
- inactive: {type: Boolean, default: false}
- });
- mongoose.model('User', User);
- mongoose.model('AuthUser', authUser);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement