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

189
Views
¿Puedo consultar las siguientes colecciones en el nodo js usando mongo?

Tengo un modelo que está construido así en el nodo js usando mongodb:

 // API FOR EDITING Shop exports.edit = async(req, res)=>{Frients, fruitID, name const {fruitTypes, fruitID, name} = req.body const parentID = req.params.id // checkin if the fruit type wanted is fruit type list await Shop.findById({_id:parentID }) .exec((error, fruit)=>{ if(error) return res.status(400).json(`error : ${error}`) if(fruit){ const fruitt = req.body.fruitTypes.fruit // checked if the particular fruit to replace ID is contained in the nested collection const isfruit = fruit.fruits.find(s=>s._id==fruitID) if(!isfruit) return res.status(`${fruitTypes.fruit} did't match our records`) // find a particular shop ID and replace the nested collects values with given one const saved = Shop.findByIdAndUpdate({_id: fruitID}, { "$set":{ "fruitTypes" : fruitTypes } }) console.log(saved) saved.save() res.status(200).json("I tem edited") } }) }

Lo que quiero lograr es la capacidad de eliminar y agregar frutas en FruitType [subcolección]. Cada tienda pertenece a una persona y puede poner tantos tipos de frutas como desee en la matriz fruitType y puede eliminar solo una a la vez reemplazando la fruta sin eliminar otros frentes en la misma subcolección FruitType.

He intentado usar FindByIdAndUpdate pero no me funciona.

Este es mi modelo:

 const {Schema, model} = require('mongoose') const ShopSchema = new Schema({ name:{ require: true, type: String, }, fruitType:[ { fruit:{type: String} } ], }
about 4 years ago · Juan Pablo Isaza
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!