Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
¿Cómo puedo verificar si un usuario ya existe en mongoDB?

Estoy creando un sistema de creación de cuentas con express.js pero quisiera saber como puedo saber si el usuario ya tiene una cuenta (con su correo) en mi BD para no registrarlo dos veces.

 const router = require("express").Router(), User = require("../database/models/User.model.js"); const cryptoJS = require("crypto-js"); //REGISTER router.post("/register", async (req, res) => { const { username, email, password } = req.body; if (User.findOne({ email: email })) { return res.status(400).json({ message: "This email is alredy existing in our database" }); } else { const user = new User({ username: username, email: email, password: cryptoJS.AES.encrypt( password, process.env.CRYPTO_KEY ) }); await user.save() .catch(err => res.status(500).json({ error: err.message })); } }); module.exports = router;

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

const router = require("express").Router(), const User=require("../database/models/User.model.js"); const cryptoJS = require("crypto-js"); //REGISTER router.post("/register", async (req, res) => { const { username, email, password } = req.body; const checkUser = await User.findOne({ email: email }) if (checkUser) { return res.status(400).json({ message: "This email is alredy existing in our database" }); } else { const user = new User({ username: username, email: email, password: cryptoJS.AES.encrypt( password, process.env.CRYPTO_KEY ) }); await user.save() .then(data=>res.json(data)) .catch(err => res.status(500).json({ error: err.message })); } }); module.exports = router;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!