Extending the users package of mean.io

爷,独闯天下 提交于 2019-12-04 23:57:04

问题


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



来源:https://stackoverflow.com/questions/25781499/extending-the-users-package-of-mean-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!