多用户应用程序的Mongoose模式

我需要为我需要使用MongoDB,Express,AngularJS和NodeJS开发的多用户应用程序构build模式。 我在该应用程序中有4种types的用户, GUESTREGISTERED_USERSUBSCRIBERADMIN 。 一旦用户注册了应用程序,我需要根据特定用户的angular色显示表单和信息。

有人可以给我一些关于如何处理用户不同angular色的架构的想法,因为我以后可以将其用于angular色和访问级别function?

例如,以下registeredUserSchema对于REGISTERED_USERSUBSCRIBERADMIN用户是常见的:

 var registeredUserSchema = mongoose.Schema({ userId: String, fullName: String , email: String, password: String, created: { type: Date, default: Date.now }, roles: [String] }); 

但是后来我需要一个SUBSCRIBERangular色的用户需要大量的信息,所以一旦他注册了应用程序,我想要显示很多额外的信息,以显示他填写他的相关信息,而不是只有REGISTERED_USER用户。

有人可以帮我吗?

编辑:更多的解释

例如, REGISTERED_USER将具有userId ,但具有SUBSCRIBERangular色的用户将具有subscriberId 。 所以我需要决定如何构build数据,因为所有用户都有共同的数据,然后根据他的angular色为每个用户提供不同的数据。 我需要帮助select构build数据的策略。 例如,在Java Persistence API中,我们有多种inheritance策略来构造关系数据库表中的数据。

我在这个部分使用这个集合:

 var permissions_schema = mongoose.Schema({ name : String, title : String }); // this are mostly static data var roles_schema = mongoose.Schema({ name : String, title : String, _permissions : Array });// _permissions is an array that contain permissions _id var contacts_schema = mongoose.Schema({ mobile : String, password : String, first_name : String, last_name : String, _role : Number, _enabled : Boolean, _deleted : Boolean, _verify_code : Number, _groups_id : Array, _service_id : String }); // and at last _role is _id of the role which this user owns. 

像这些集合,你可以轻松地pipe理你的用户。 我希望这些对你有好的想法。

更新:一个更灵活的模式可以有联系对象中的role_id数组,联系人可以有许多angular色,他/她的权限是所有angular色权限的合并。

以下是来自MEAN.JS yeoman脚手架生成器的用户模式:

  var UserSchema = new Schema({ firstName: { type: String, trim: true, default: '', validate: [validateLocalStrategyProperty, 'Please fill in your first name'] }, lastName: { type: String, trim: true, default: '', validate: [validateLocalStrategyProperty, 'Please fill in your last name'] }, displayName: { type: String, trim: true }, email: { type: String, trim: true, default: '', validate: [validateLocalStrategyProperty, 'Please fill in your email'], match: [/.+\@.+\..+/, 'Please fill a valid email address'] }, username: { type: String, unique: 'testing error message', required: 'Please fill in a username', trim: true }, password: { type: String, default: '', validate: [validateLocalStrategyPassword, 'Password should be longer'] }, salt: { type: String }, provider: { type: String, required: 'Provider is required' }, providerData: {}, additionalProvidersData: {}, roles: { type: [{ type: String, enum: ['user', 'admin'] }], default: ['user'] }, updated: { type: Date }, created: { type: Date, default: Date.now }, /* For reset password */ resetPasswordToken: { type: String }, resetPasswordExpires: { type: Date } });