How to update document

SO update should happen when

  1. _id is =“4617a874-9a8a-4b57-b9f6-6c0c83e4c0f8”
    2._type =“AssetDef”
    3.maintenance _id is matching _id = “50a0c62b-f7b2-4fba-ac51-19e0976c8760”
    THEN it should update : this value "mos_fixDate": false to mos_fixDate": true

THIS IS THE DOCUMENT
{
“_id”: “4617a874-9a8a-4b57-b9f6-6c0c83e4c0f8”,
“_type”: “AssetDef”,
“maintenance”: [
{
"_id": “50a0c62b-f7b2-4fba-ac51-19e0976c8760”,
“description”: “nekaj6”,
“duration”: 3,
“maintenanceName”: “nekaj6”,
"mos_fixDate": false,
“period”: 3,
“type”: “preventiveMaintenance”
},
{
“_id”: “fa022b93-c9f8-4c45-a33b-98d5c7ae74e3”,
“description”: “ma neki neki”,
“duration”: “40”,
“label”: “test 123”,
“maintenanceName”: “test 123”,
“period”: 1000,
“type”: “preventiveMaintenance”
},
{
“_id”: “ec159947-32a8-4cac-b455-f1e66e0122a8”,
“description”: “nekaj12”,
“duration”: “4”,
“label”: “nekaj123”,
“maintenanceName”: “nekaj123”,
“period”: 500,
“type”: “preventiveMaintenance”
},
{
“_id”: “23a85b6a-f9b0-4736-9b38-ba26e4c6a975”,
“description”: “asfasf 2”,
“duration”: 5,
“maintenanceName”: “test ali dela3”,
“period”: 5,
“type”: “preventiveMaintenance”
},
{
“_id”: “26fc06c4-bce0-46c9-a93b-60d1b04e3b39”,
“description”: "sda dsaw ",
“duration”: 2,
“maintenanceName”: “test test”,
“period”: 2,
“type”: “preventiveInspection”
},
{
“_id”: “b5b31ef8-2c3a-435e-b05c-7ecafc9dc3a5”,
“description”: “par razlik je narejenih”,
“duration”: 600,
“maintenanceName”: “Novi maintenance”,
“period”: 36000,
“type”: “preventiveMaintenance”
},
{
“_id”: “20d3115d-ffb0-4a58-9196-5bcf7162677c”,
“description”: “nekaj1”,
“duration”: “5”,
“maintenanceName”: “nekaj5”,
“period”: 3,
“type”: “unplannedMaintenance”
},
{
“_id”: “037454a4-47a9-4708-a315-81abd9ab14c8”,
“description”: “asfdasf”,
“duration”: 100,
“maintenanceName”: “aaaaaa123”,
“period”: 100,
“type”: “preventiveMaintenance”
}
]
}

You can try:

update default d
set m.`mos_fixDate` = true 
    for m in d.maintenance when m._id = "50a0c62b-f7b2-4fba-ac51-19e0976c8760" end 
where d._id = "4617a874-9a8a-4b57-b9f6-6c0c83e4c0f8" 
and d._type = "AssetDef";

HTH.

1 Like

Thank you really much ! It would take me some time to figure it out