Extending the users package of mean.io

2019-03-29 09:50发布

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条回答
男人必须洒脱
2楼-- · 2019-03-29 10:45

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

查看更多
登录 后发表回答