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

152
Views
rellenar la clave de mangosta como parte del objeto

EDITAR
repositorio de reproducción mínima

Es más fácil de explicar en código que en inglés. El siguiente código funciona, pero parece que tiene que haber una manera más fácil, más MongoDBy/mongoosy...

 // recipeModel.js, relevant part of the schema equipments: [{ _id: { type: Schema.Types.ObjectId, ref: 'equipments', }, quantity: { type: Number, required: true, }, }], // recipeController.js const equipmentsWorkaround = recipe => Object.assign({}, recipe.toObject(), { equipments: recipe.toObject().equipments.map(equip => ({ quantity: equip.quantity, name: equip._id.name, _id: equip._id._id, })), }) const getItem = (req, res, next) => { Recipes.findById(req.params.id) .populate('equipments._id') .then(equipmentsWorkaround) // <--- ugh ... .then(recipe => res.json(recipe)) .catch(next) }

Sé cómo hacer una ref "convencional" en mongoose, pero ¿lo que busco aquí es posible en mongo?

resultado deseado:

 equipments: [ { quantity: 1, name: "Pan", _id: 'some mongo object here...' }, { quantity: 3, name: "Big Knife", _id: 'some mongo object here...' } ]
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!