Delete a field with no specific name in couchbase document

Hi!
So I’m trying to unset some fields in a document. The issue is that that field does not have a specific name. I’ll show you an example:

{
“collection”: “holiday-schedule”,
“holidays”: {
“2023-05-01”: {
“creation_date”: “2023-06-20T10:53:30Z”,
“holiday_date”: “2023-05-01”,
“update_time”: “2023-06-20T10:53:31Z”
},
“2023-09-03”: {
“afternoon_closing_time”: “17:30:00”,
“creation_date”: “2023-08-25T13:52:54Z”,
“holiday_date”: “2023-09-03”,
“morning_opening_time”: “10:00:00”,
“update_time”: “2023-08-25T13:52:55Z”
},
“2023-09-15”: {
“creation_date”: “2023-08-30T13:30:47Z”,
“holiday_date”: “2023-09-15”,
“update_time”: “2023-08-30T13:30:49Z”
},
“2024-08-15”: {
“update_time”: “2024-03-11T09:40:18Z”,
“creation_date”: “2024-03-08T08:44:33Z”,
“holiday_date”: “2024-08-15”
}
},
“store_code”: “10”,
“update_time”: “2024-03-11T09:40:19Z”
}

I need to delete the ones that include dates from 2023 (i.e. “2023-05-01”,“2023-09-15”…) and keep the ones from 2024. If you can help me with this, I will appreciate it so much.

You can try:

UPDATE myBucket b
UNSET b.[n] FOR n:v IN b WHEN n LIKE '2023-%' END
WHERE ...

[Edit:]
Extending for a sub-element:

UPDATE myBucket b
UNSET b.subField.[n] FOR n:v IN b.subField WHEN n LIKE '2023-%' END
WHERE ...

HTH.

1 Like