public
Created

Custom Schema

  • Download Gist
schema.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
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;
//--------------------------------------
 
 
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.