Using N1ql to update/replace an array element and matching three conditions

Viewed 105

SO update should happen when

_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

```
{
“_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”
}
]
}

Expecing:

```
{
“_id”: **“4617a874-9a8a-4b57-b9f6-6c0c83e4c0f8”** = MATCHING ,
“_type”: “**AssetDef**”, = MATCHING 
“maintenance”: [
{
**"_id": “50a0c62b-f7b2-4fba-ac51-19e0976c8760”,** = MATCHING 
“description”: “nekaj6”,
“duration”: 3,
“maintenanceName”: “nekaj6”,
"mos_fixDate": **true**,
“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”
}
]
}

I tried :

UPDATE i4c USE KEYS "maintenance"

SET maintenance[i] = {"mos_fixDate":true}

FOR i : a IN maintenance WHEN a._id="50a0c62b-f7b2-4fba-ac51-19e0976c8760" END RETURNING maintenance

AND _id = "4617a874-9a8a-4b57-b9f6-6c0c83e4c0f8"

1 Answers
Related