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

132
Views
Why is mongoose changing variable

It seems like mongoose (5.6.11) is changing my value in a query. Is this normal? Is there a way to keep the string case the same?

console.log('>>',req.body.visitor)
Visitor.findOne({ email: req.body.visitor.email }).then((visitor)=>{
....

server console/log:

>> {
  email: 'Maida_VonRueden@hotmail.com',//this is a fake email generated with faker
  enteredValidationCode: '969621'
}
Mongoose: visitors.findOne({ email: 'maida_vonrueden@hotmail.com' }, { projection: {} })
//                                   ^ Why does the email change here?

Do I have to use regex to query case insensitive (Visitor.findOne({email: {$regex: new RegExp(req.body.visitor.email, 'i')}}))?

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

0

Based on @AKX comment my schema required lowercase

email: {
    type: String,
    unique: true,
    lowercase: true, // < HERE
    required: [true, 'cant be blank'],
    match: [/\S+@\S+\.\S+/, 'is invalid'],
    index: true
}

Per doc

boolean, whether to always call .toLowerCase() on the value

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!