Couchbase update in array of ids

Hello all,

I have two documents:

DocA : 
status: pending,
type:  title,

and second document:

newTitleId: DocA,
oldTitleId: [DocC, DocD],
type: merged

What im trying to achieve is having only DocA id, id like to update DocA status to ‘deleted’ and then DocC and DocD status to ‘pending’ .

My current approach is

  1. To set DocA status to deleted:

    UPDATE myBucket
    SET status = ‘DELETED’
    WHERE meta().id = ‘DocA’

this one is fairly simple, but im struggling with the second part, to update DocC and DocD status. My approach is as follows:

UPDATE myBucket
SET status = ‘PENDING’
WHERE meta().id IN 
(SELECT oldTitleId from myBucket where type = "merged" and newTitleId = 'DocA’)

Basically what im trying to do is get all the Ids that exist inside DocB.oldTitleId in the last WHERE but it seems im doing something wrong that I cannot figure out, any ideas?

UPDATE myBucket AS b USE KEYS ARRAY_FLATTEN((SELECT RAW oldTitleId FROM myBucket WHERE type = "merged" AND newTitleId = "DocA"),1)
SET b.status = "PENDING";

Awesome! works like a charm

Hey, thanks for the fast reply, I have modified the query a little bit to look like this:

(SELECT RAW titles
from myBucket as m
where (type = ‘merged’ and newTitleId = ‘some_id_here’)),
(SELECT RAW meta().id
from myBucket as s
where parentId = ‘some_id_array’ and (type = ‘editted’ or type = ‘territory’))),1)
SET m.status = ‘PENDING’;

My only issue I want to achieve right now is that in the place of the last where clause parentId = some_id_array
I would like to have another inner query which would return an array of strings and id like to do a foreach

Use IN clause parentId IN some_id_array