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

142
Views
Mongoose: ¿Cómo agregar APP_URL a imageURL al recuperar datos de una sola imagen?

En ImageSchema , tengo algunos campos: title , imageURL de imagen. Cuando recupero datos de una sola imagen, quiero agregar http://localhost:4000/ a imageURL.

"imageURL": "http://localhost:4000/uploads/photo-1508919801845.jpeg",

Datos de ejemplo:

 { "_id": "612e0328c1c6dd25c6f14fd4", "title": "photo-1508919801845", "imageURL": "/uploads/photo-1508919801845.jpeg", "createdAt": "2021-08-31T10:23:36.419Z", "updatedAt": "2021-08-31T10:23:36.419Z", "__v": 0 }

Controlador.ts

 const imageId = req.params.id const findImage = await Image.findOne({ _id: imageId}) if (!findImage) { return res.status(404).json({error: true, msg: "Image not found"}) } const image = await Image.findById({_id: imageId}).select({ _id: 0, __v: 0}) return res.status(200).json({ error: false, data: image })

¿Cómo puedo hacer eso?

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

0

Puede usar la canalización de Aggregation con el operador $concat :

 Image.aggregate([ { "$match": { "_id": "612e0328c1c6dd25c6f14fd4" } }, { "$set": { "imageURL": { "$concat": [ "http://localhost:4000", "$imageURL" ] } } } ])

ejemplo de trabajo

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!