因此,我刚刚开始了一个 meteor 项目,并包括了accounts-password软件包。该软件包仅支持少量密钥。我想向用户集合添加一个新的SimpleSchema,其中包含更多字段。

我不被允许使用创建另一个用户集合实例

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

我可以附加一个架构,但是将不得不保留许多可选字段,否则可能无法向默认程序包注册。

是否可以在不将其他字段设置为可选且仍然能够正确登录的情况下添加simpleSchema?

或者在这种情况下还有其他解决方法吗?

预先感谢您的帮助

最佳答案

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

@users = Meteor.users;

您可以在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
    }
});

08-15 18:30