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

219
Views
cómo actualizar el segundo esquema usando el nodo js (mongdb)

Estoy tratando de actualizar mi segundo esquema que tiene referencia en el primer esquema

propietarioEsquema.js

 var ownerSchema = Schema({ fname : String, lname : String, shopPlace : { type: Schema.Types.ObjectId, ref: 'Shop' } }); var Owner = mongoose.model('Owner', ownerSchema);

shopSchema.js

 var shopSchema = Schema({ shopName : String, location : String, startDate : Date, endDate : Date }); var Shop = mongoose.model('Shop', shopSchema);

así que estoy tratando de actualizar mi esquema de esta manera

 const update = async (req, res) => { const { id } = req.params; let update = {}; if (req.body.fname) update.fname = req.body.fname; if (req.body.lname) update.lname = req.body.lname; if (req.body.shopPlace.shopName) update.shopPlace.shopName = req.body.shopPlace.shopName; if (req.body.shopPlace.location) update.shopPlace.location = req.body.shopPlace.location; let newOwmer = new Owner.updateOne( { ownerId: id }, { $set: update, }, { runValidators: true } ); };

Estoy tratando de actualizar la tienda pero no funciona y ¿dónde me equivoco? No lo sé.

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

0

 const update = async (req, res) => { const { id } = req.params; let update = {}; let updateShop = {} if (req.body.fname) update.fname = req.body.fname; if (req.body.lname) update.lname = req.body.lname; if (req.body.shopPlace.shopName) updateShop.shopPlace.shopName = req.body.shopPlace.shopName; if (req.body.shopPlace.location) updateShop.shopPlace.location = req.body.shopPlace.location; // get shopPlace _id from Owner const { shopPlace } = await Owner.findOneAndUpdate( { _id: id }, { $set: update, }, { new:true} ); // here you must have the document you just updated. Just recover the id of the shop to modify it in turn // update shop let newShop = await Shop.findOneAndUpdate( { _id: shopPlace }, { $set: updateShop, }, {new:true} ); };
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!