Skip to content

@whito /schema.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.