如何使用meteorjs中的accounts-password包向用户集合添加collection2架构?

Sum*_*ama 7 javascript mongodb meteor meteor-accounts meteor-collection2

所以,我刚刚开始了一个流星项目,并且已经包含了帐户密码包.该软件包仅支持少量密钥.我想将一个新的SimpleSchema添加到带有更多字段的users集合中.

我不会创建另一个用户集合实例

@users = Mongo.Collection('users');
//Error: A method named '/users/insert' is already defined
Run Code Online (Sandbox Code Playgroud)

我可以附加一个模式,但将强制保留很多字段可选,否则可能无法注册默认包.

我可以添加simpleSchema而不使其他字段可选,但仍能正常登录吗?

或者这个案子还有其他工作吗?

提前感谢您的帮助

Tom*_*nik -1

您可以通过以下方式获取用户集合:

@users = Meteor.users;
Run Code Online (Sandbox Code Playgroud)

您可以在 collection2 包的文档中找到定义用户集合的很好的示例: https: //atmospherejs.com/aldeed/collection2

Schema = {};
Schema.User = new SimpleSchema({
    username: {
        type: String,
        regEx: /^[a-z0-9A-Z_]{3,15}$/
    },
    emails: {
        type: [Object],
        // this must be optional if you also use other login services like facebook,
        // but if you use only accounts-password, then it can be required
        optional: true
    },
    "emails.$.address": {
        type: String,
        regEx: SimpleSchema.RegEx.Email
    },
    "emails.$.verified": {
        type: Boolean
    },
    createdAt: {
        type: Date
    },
    profile: {
        type: Schema.UserProfile,
        optional: true
    },
    services: {
        type: Object,
        optional: true,
        blackbox: true
    },
    // Add `roles` to your schema if you use the meteor-roles package.
    // Option 1: Object type
    // If you specify that type as Object, you must also specify the
    // `Roles.GLOBAL_GROUP` group whenever you add a user to a role.
    // Example:
    // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP);
    // You can't mix and match adding with and without a group since
    // you will fail validation in some cases.
    roles: {
        type: Object,
        optional: true,
        blackbox: true
    },
    // Option 2: [String] type
    // If you are sure you will never need to use role groups, then
    // you can specify [String] as the type
    roles: {
        type: [String],
        optional: true
    }
});
Run Code Online (Sandbox Code Playgroud)