0

I want to update each element in an array(add score column with value 0) if date exists. Please provide the answer for 3.4 version without using $[] operator as this operator is not supported in 3.4 version

data is like this

{
    "u_id" : "79049",
    "array" : [
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "2",
            "date" : "2019-03-29 06:03:13"
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3",
            "date" : "2019-03-29 06:03:13"
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3"
        }
    ],
    "Status" : 1
}

data I want in this manner

{
    "u_id" : "79049",
    "array" : [
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "2",
            "date" : "2019-03-29 06:03:13",
            "score":0
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3",
            "date" : "2019-03-29 06:03:13",
            "score":0
        },
        {
            "duration" : 1,
            "lag" : 0,
            "Type" : "3"
        }
    ],
    "Status" : 1
}
Sumit Tiwari
  • 139
  • 1
  • 8
  • Can you edit the question, select all the JSON code, and hit CTRL + K (to format it as code) please? It's very difficult to read. You should also provide some example of what you've tried - how are you processing the data (checking array elements)? – ron_g Apr 02 '19 at 11:29
  • There are more solutions listed in the existing answers than just those using MongoDB 3.6 and above. If you have a lower version ( and you shouldn't because you would not be able to get official support ) then those answers would apply. – Neil Lunn Apr 03 '19 at 07:05

0 Answers0