【问题标题】:Meteor: Accounts.createUser throws exception: meteor.roles.$name_1 dup keyMeteor:Accounts.createUser 抛出异常:meteor.roles.$name_1 dup key
【发布时间】:2016-01-24 15:29:06
【问题描述】:

尝试在注册时将新用户添加到users 集合。

在 Meteor 的客户端,我调用了一个服务器方法将用户添加到users 集合中

Meteor.methods({
    createUserServer : function (user) {

        // On server-side, Accounts.createUser is essentially
        // blocking (Fibers): it waits for the user to be
        // created, and then returns its newly generated id.
        try {
            var userId = Accounts.createUser(user)
            console.log('user ID: ' , userId);
            return { success:true , message : userId }
        } catch (e) {
            console.log('Meteor Exception: ',e);
            return { success : false , message : e.reason }
        }






    }
})

添加仅在第一次users 集合上很好地发生,但在那之后,我得到了这个异常:

Meteor Exception: { [MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: meteor.roles.$name_1 dup key: { : null }] stack: [Getter] }

我检查了数据库上的roles集合,我发现只有一个文档:

db.roles.find() --> 返回 --> { "_id" : "whef5ZW8sBchDWBuH", "userId" : "WNM7gYDusa2dJY8wd", "roles" : [ ] }

我不确定这是什么类型的问题?

【问题讨论】:

    标签: javascript meteor meteor-blaze meteor-accounts meteor-autoform


    【解决方案1】:

    我明白了。

    由于某种原因,name 文档被制作为索引且唯一,这导致了上述冲突,通过删除该索引,现在一切正常:

    Meteor.roles._ensureIndex('name', {unique: 1})
    

    现在我很高兴:)

    参考:https://github.com/orionjs/orion/issues/239

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2018-05-29
      • 2013-05-24
      • 2011-05-30
      • 1970-01-01
      • 2011-02-25
      相关资源
      最近更新 更多