I am trying to create an application for sports event management system using MEAN.io
Since it uses the modular approach, there are different packages that comes in skeleton application like system
, users
, access
. What i want to do is make a new package called players
and it should extend the users package. The players schema would contain extra fields section
and teams
.So how do I extend the User Schema of users
package in players
package?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can make your players package be dependent on users.
Players.register(function(app, auth, users, database) {...});
You now have access to the database and can load the user schema with
var userModel = database.connection.model('User');
and you can use the schema.add function to extend the schema
userModel.schema.add({ scrore: 'string'});
This should add the score field to the user model
I think this might work for you. But I was told from a member of mongoose team that schema.add only works before compiling the model. See this link for more info about schema add http://mongoosejs.com/docs/api.html#schema_Schema-add