Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
How to check email and mobile and aadhar number present or not in my mongodb database?
const express = require('express');
const router = express.Router();

require('../db/conn');
const User = require('../model/userSchema');

router.get('/', (req, res) => {
    res.send(`Hello World from the server from router.`);
});

router.post('/register', (req, res) => {
    
    const { name,email,phone,work,password,cpassword } = req.body;
    
    if(!name || !email || !phone || !work || !password || !cpassword){
        return res.status(422).json({error:"please fill all the fields data.."});
    }
    User.findOne({ "$or": [ { email: email }, { phone: phone} ] })
    .then((userExist) => {
        if(userExist){
            return res.status(422).json({error:"Email ID or Mobile No is already exist."});
        }

            const user = new User({name,email,phone,work,password,cpassword});
            
            user.save().then(() => {
                res.status(201).json({message:"User Registered Successfully."});
            }).catch((err) => res.status(500).json({error:"Failed to regsiter user."}));
    }).catch(err => { console.log(err)});
});
module.exports = router;

await User.findOne({ "$or": [ { email: email }, { phone: phone} ] });

This code worked for me. But if we want to differentiate both phone and email and aadhar number; so if email id is present than it will show it is present, and if phone no is present than it will show it is present, and if aadhar no is present than it will show. To do this how can we write the syntax?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can always check userExist, which is the returned record from DB.

if(userExist.phone==phone)
 err="Phone No exist"
else if (userExist.aadhar==aadhar)
 err="Aadhar Exist"

Finally return the error string

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda