0

I have a data on MongoDB database which structure is

{
    _id: 12478565,
    products: { name: 'Mackbook Pro', price: 150000, color: 'silver' }
}

I want to update the products price and I write like this, but it gives an error

productsCollection.updateOne({_id: '12478565'}, {$set: {products.price: 190000} })

I want to know how can I modify the data in nested object?

0

1 Answer 1

1

put product.price in qoute

db.collection.update({
  _id: "12478565"
},
{
  $set: {
    "products.price": 190000
  }
})

https://mongoplayground.net/p/QxAK0LClF-8

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.