Skip to content

Instantly share code, notes, and snippets.

@whito
Created September 6, 2012 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whito/3657063 to your computer and use it in GitHub Desktop.
Save whito/3657063 to your computer and use it in GitHub Desktop.
Custom Schema
customSchema(function () {
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var Schema = mongoose.Schema, ObjectId = Schema.ObjectId;
//-----------------------------
var UserSchema = new Schema({
email: { type: String, required: true },
password: { type: String, required: true },
_role: { type: Schema.Types.ObjectId, ref: 'Role' },
_teams: [{ type: Schema.Types.ObjectId, ref: 'Team' }]
});
var User = mongoose.model('User', UserSchema);
User.modelName = 'User';
module.exports['User'] = User;
//-------------------------------
var RoleSchema = new Schema({
name: { type: String, required: true },
active: {type: Boolean, default: true}
});
var Role = mongoose.model('Role', RoleSchema);
Role.modelName = 'Role'; // this is for some features inside railway (helpers, etc)
module.exports['Role'] = Role;
//--------------------------------------
var TeamSchema = new Schema({
name: { type: String, required: true }, // the role name (eg. Agent, Admin)
active: {type: Boolean, default: true} // active or not
});
var Team = mongoose.model('Team', TeamSchema);
Team.modelName = 'Team';
module.exports['Team'] = Team;
//--------------------------------------
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment