Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Update data in MongoDB Model in intervals

I am making a login system. I am trying to make user wait for 5 minutes when login attempts exceed 3 times, here is the User Model:

const mongoose = require("mongoose");
const validator = require("validator");
const bcrypt = require("bcryptjs");
const jwt = require("jsonwebtoken");
const crypto = require("crypto");

const UserSchema = new mongoose.Schema({
  // Other Model Schemas
  loginAttempts: { type: Number, default: 0 },
});

//Functions - Other functions above

// I am trying to make user wait for 5 minutes when login attempts exceed 3.
// But this is not working.

if (this.loginAttempts > 3) {
  setTimeout(() => {
    this.loginAttempts = 0;
    this.save();
  }, 1000 * 60 * 5);
}
if (this.loginAttempts >= 1) {
  setTimeout(() => {
    this.loginAttempts = 0;
    this.save();
  }, 1000 * 60 * 60 * 60 * 1);
}

const User = mongoose.model("User", UserSchema);
module.exports = User;

I was searching UserSchema.<parameter>, I was searching parameters or function (sorry I don't know the exact term) which works like setTimeout() or setInterval() which checks on model and updates data like I have tried in above if(){} statement.

Can anyone suggest me a function in Schema which checks on intervals and update data as the time runs out just like, setTimeout function and setInterval function

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda