alexa

Update String inside object inside array mongodb in nodejs ?

Update String inside object inside array mongodb in nodejs ?

Try This 

 db.collection.update({
  "_id": ObjectId("000000000000000000000001"),
  "side1.username": "test1"
},
{
  "$set": {
    "side1.$.id": "43242342"
  }
}) 

Try it on

Example updated document:

 [
  {
    "_id": ObjectId("000000000000000000000001"),
    "side1": [
      {
        "id": "43242342",
        "username": "test1"
      },
      {
        "id": "id2",
        "username": "test2"
      },
      {
        "id": "id3",
        "username": "test3"
      }
    ],
    "side2": [
      {
        "id": "id4",
        "username": "test4"
      },
      {
        "id": "id5",
        "username": "test5"
      },
      {
        "id": "id6",
        "username": "test6"
      }
    ]
  }
]

252 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry