ParallelSaveError:不能并行多次保存()同一个doc

时间:2018-06-05 11:19:15

标签: node.js express mongoose passport.js

我将我的本地数据库移到了mLab的免费套餐中,我收到了一个我以前没有得到过的错误。 ParallelSaveError: Can't save() the same doc multiple times in parallel

错误从第user.save()行开始。 你能看看,请说明如何解决它?我迷路了...

// Confirm password.
// Execs after requiresAuth permission resolver.
const confirmPassword = ({ user, inputs: { password } }) => {
  // Validate args.
  validate([required, isLength], 'PASSWORD', password)

  // Required for graphql. Expects a promise.
  return new Promise((resolve, reject) =>
    user.comparePassword(password, (err, isMatch) => {
      if (err) return reject(err)
      if (!isMatch) return reject(error('CONFIRM_PASSWORD_FAILED'))
      return resolve(user)
    })
  )
}
// Compare submitted plain text password with the salted and hashed version.
    UserSchema.methods.comparePassword = function(candidatePassword, callback) {
      return bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
        if (isMatch) {
          this.account.authStrikes = 0
          this.account.lastConfirm = Date.now()
        } else {
          this.account.authStrikes += 1
          if (this.account.authStrikes === 3) {
            this.account.status = 'locked'
            require('../resolvers/auth')
              .createUnlockAccountToken({ userId: this._id })
          }
        }
        return this.save()
          .then(() => callback(null, isMatch))
          .catch(err => callback(err))
      })
    }

0 个答案:

没有答案