帐户密码问题:重复密钥错误索引:meteor.users。$ emails.address_1

时间:2014-05-11 11:33:57

标签: meteor meteor-blaze

我仅在生产生产时遇到以下错误。我已经测试了开发它的作品非常好。

Exception while invoking method 'createUser' MongoError: insertDocument :: caused by :: 11000 E11000 duplicate key error index: meteor.users.$emails.address_1  dup key: { : "damianmiles@gmail.com" }
    at Object.Future.wait (/home/Steven/bundle/programs/server/node_modules/fibers/future.js:326:15)
    at null.<anonymous> (packages/meteor/helpers.js:111)
    at MongoConnection.(anonymous function) [as insert] (packages/mongo-livedata/mongo_driver.js:595)
    at Meteor.Collection.(anonymous function) [as insert] (packages/mongo-livedata/collection.js:476)
    at Object.Accounts.insertUserDoc (packages/accounts-base/accounts_server.js:1021)
    at createUser (packages/accounts-password/password_server.js:557)
    at packages/accounts-password/password_server.js:577
    at tryLoginMethod (packages/accounts-base/accounts_server.js:171)
    at Object.Accounts._loginMethod (packages/accounts-base/accounts_server.js:287)
    at Meteor.methods.createUser (packages/accounts-password/password_server.js:563)

这是/clients/lib/accounts.js文件中的代码:

Template.register.events({
'submit #register-form' : function(e, t) {
    e.preventDefault();
    var name = t.find('#signupFullName').value,
        email = trimInput(t.find('#signupEmail').value.toLowerCase()),
        subdomain = t.find('#signupSubdomain').value,
        password = t.find('#reenterpassword').value,
        repassword = t.find('#reenterpassword').value;

    if(password != repassword) {
        alert('Password not matches');
    }

    if (isValidPassword(password) == false || isEmail(email) == false) {
        return false;
    }


       Accounts.createUser({email: email, password: password, profile: {name: name}}, function(err) {
           if (err) {
                alert(err.message);
           } else {
                alert('Account has been created.');

                Meteor.navigateTo('/ControlPanel');
                $('#myModal').modal('hide');
           }
       });

       return false;
    }
}

});

发展: meteor:0.8.1.1,Nodejs:v0.10.25

生产: MongoDB:2.6.1(32位),NodeJS:v0.10.26

1 个答案:

答案 0 :(得分:1)

此错误表示:

  1. users.emails.address上有唯一索引。
  2. 存在电子邮件'damianmiles@gmail.com'
  3. 的用户
  4. 您正在尝试使用相同的电子邮件插入新用户。
  5. 默认情况下,meteor不会添加用户电子邮件的唯一索引,但这是完全合理的事情。事实上,如果你没有索引流星仍然会阻止新用户被创建 - 但它会引发不同的错误。

    如果您连接到生产数据库并运行:

    > db.users.findOne({'emails.address': 'damianmiles@gmail.com'});
    

    你应该得到一个结果。如何处理这些信息取决于您 - 可能会删除旧用户,尝试使用其他电子邮件地址插入等。

    对于类似问题,另请参阅this