Users of mean.io package extension

I am trying to create an application for a sports event management system using MEAN.io Since it uses a modular approach, there are various packages that are included in the skeleton application, for example system , users , access . I want to make a new package called players , and it should expand the users package. The player map will contain additional section and teams fields. So how can I extend the user schema of the users package in the players package?

+5
source share
1 answer

You can make your player pack dependent on users.

Players.register(function(app, auth, users, database) {...});

Now you have access to the database and you can load the user schema using

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 a rating field to the user model.

I think this might work for you. But I was told by a member of the mongoose team that schema.add only works until the model is compiled. See this link for more information on the add scheme http://mongoosejs.com/docs/api.html#schema_Schema-add

+4
source

Source: https://habr.com/ru/post/1202314/


All Articles