0

I have a small problem with findByIdAndUpdate in mongoose:

my code:

const editCarrito = await Carrito.findByIdAndUpdate(req.params.id, {pedido:{ cantidad: cantidad, bebidas:bebidas.toString(), rentrega: rentrega}, comentarios:{vegetariano: vegetariano.toString(),retirar: retirar, adicional: adicional}})

The problem:

I have this data stored in mongoDB:

enter image description here

saving editcarrito deletes important data such as type, name, platoid. I need that data to remain there and that is why I do not include them in order thinking that by not being there will not modify anything as happens with image or userid:

enter image description here

any ideas? Thanks in advance :)

1 Answer 1

0

i found the solution :)

const editCarrito = await Carrito.findByIdAndUpdate(req.params.id, {$set: { 'pedido.cantidad': cantidad, 'pedido.bebidas':bebidas.toString(), 'pedido.rentrega': rentrega}})

the property set is the key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.