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

235
Views
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 answers
Answer question

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 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!