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

251
Views
MongooseJS: cómo eliminar 1 objeto dentro de Array en Array of Objects

¡Hola, expertos de MongooseJS !

Soy nuevo en MongooseJS , este es mi segundo día para resolver este problema, pero no puedo encontrar una solución que funcione.

¡Gracias de antemano!

Mi método de eliminación

 Cart.updateOne( { "content.merchantId": req.body.merchantId }, { $pull: { "content.items._id": req.body.productId } }, { new: true }, function (error, result) { if (error) { } else if (result) { } } );

Esquema

 const CartSchema = new Schema({ customerId: { type: String, required: true, }, content: { merchantName: { type: String, required: true, }, merchantId: { type: String, required: true, }, items: [], }, });

JSON de muestra

 [ { "content": { "merchantName": "SAMPLE_MERCHANT_NAME", "merchantId": "SAMPLE_MERCHANT_ID", "items": [ { "_id": "SAMPLE_ID", "title": "SAMPLE TITLE", } ] }, "_id": "618220e83966345ab5d451cd", "__v": 0 }, ]

Mensaje de error

 Cannot use the part (_id) of (content.items._id) to traverse the element ({items: [{ _id: "SAMPLE_ID", title: "SAMPLE TITLE"}] })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

deberías usar así

 db.collection.update({ "content.merchantId": "SAMPLE_MERCHANT_ID" }, { $pull: { "content.items": { "_id": "SAMPLE_ID" } } }, { new:true }, )

https://mongoplayground.net/p/Ou26tab2mBU

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!