-1

I need to modify the item text in the last element to be "Here is 3".

The collection is named "tickets".

{
  "_id": "5d7809b728468a06de12982b",
  "status": "New",
  "actionList": [
    {
      "actionName": "Show To Customer",
      "createTime": "2019-09-10T20:39:49.479Z",
      "text": "Here is 1"
    },
    {
      "actionName": "Commented",
      "visibilityLevel": 10,
      "text": "Here is 2"
    },
    {
      "actionName": "Commented",
      "visibilityLevel": 10,
      "text": "Here is 4"
    }
  ]
}

Based on other one this doesn't work;

update( {_id:ObjectId('5d852656b1348d6c9a043872'), actionList.0 : "Here is 4"}, {$set: {"actionList.$" : "Here is 3"}})
Dharman
  • 30,962
  • 25
  • 85
  • 135
user2568374
  • 1,164
  • 4
  • 11
  • 21
  • Possible duplicate of [MongoDB: How do I update a single subelement in an array, referenced by the index within the array?](https://stackoverflow.com/questions/11372065/mongodb-how-do-i-update-a-single-subelement-in-an-array-referenced-by-the-inde) – Himanshu Sharma Sep 23 '19 at 17:21
  • the word 'content' in the other one is not clear. I can't tell if that is a key word or part of the text. – user2568374 Sep 23 '19 at 17:25

1 Answers1

0

found another solution:

update( {"_id":ObjectId("5d7809b728468a06de12982b")}, {$set:{"actionList.2.text" : "Here is 3"}})
user2568374
  • 1,164
  • 4
  • 11
  • 21