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

92
Views
lanza un error cuando $match no encuentra ningún documento coincidente

Tengo el siguiente código:

 const userSchema = new mongoose.Schema({ name: String, loginAttempts: [ { IP: String } ] }) const User = mongoose.model('User', userSchema, 'users')
 app.get('/users/:userId/login-attempts', async(req,res,next)=>{ const loginAttempt = await User.aggregate([ { $match: { _id: mongoose.Types.ObjectId(req.params.userId) } }, { $unwind: '$loginAttempts' }, { $replaceRoot: { newRoot: '$loginAttempts' } }, ]) })

Quiero que cuando el operador $match no encuentre un documento coincidente arroje un error para informar algo al menos, para mostrarle al cliente un mensaje real de que el req.params.id que está buscando no existe en la primera etapa.

¿Pero cómo?

about 4 years ago · Santiago Trujillo
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!