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

125
Views
¿Cómo verificar si un objeto ya ha sido creado?

Hola, me gustaría verificar si se creó un objeto. Si se crea, redirija a la página de identificación, pero si no se crea, redirija a la página donde se está creando.

Aquí está mi aplicación

 app.get('/my',isLoggedIn,async (req,res)=> { const safe= await Safe.find({}); if(safe===undefined){ res.redirect('/mysafe') } else { res.redirect(`mysafe/${safe._id}`) } })

Creo que debería funcionar, pero recibo un error de conversión CastError: Cast to ObjectId falló por el valor "indefinido" (tipo cadena) en la ruta "_id" para el modelo "Seguro"

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

0

Solo necesita cambiar su condicional y usar if(safe) como condición. Eso será verdadero si el objeto ha sido creado y falso si no. Algo del estilo de:

 app.get('/my', isLoggedIn, async (req,res) => { const safe= await Safe.find({}); if(safe){ res.redirect(`mysafe/${safe._id}`) } else { res.redirect('/mysafe') } })

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!