• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

242
Views
Eliminar un objeto de la matriz usando MongoDB

Estoy intentando eliminar un producto del carrito del usuario cuando lo elimino de la web, pero no se como hacerlo.

El esquema moongoose de User es el siguiente:

 var schema = mongoose.Schema({ email: { type: String, required: true }, password: { type: String, required: true }, name: { type: String, required: true }, surname: { type: String, required: true }, address: { type: String, required: true }, birth: { type: Date, required: true }, cartItems: { type: [{ qty: { type: Number, required: true }, product: { type: mongoose.Schema.Types.ObjectId, ref: 'Product' } }] } });

Quiero eliminar un artículo de cartItems. ¿Cómo puedo hacerlo?

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

db.collection.update( { _id: id }, { $pull: { 'cartItems.type': { product: '....' } } } );

más sobre$tirar

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error