问题
I have the following n1ql
query:
UPDATE default
USE KEYS '557a7628-1217-4974-95cf-d64247c560cd'
SET p.last_seen_message_id = 'e5010536-7fde-42c1-9fea-e4a29e560f53', p.last_seen_message_text = 'hello'
FOR p IN participants WHEN p.id = '119c35ab-a1cc-4e9f-bab5-d58d6d396623' END
WHERE doc_type = 'conversation'
RETURNING default.*
With this query, I would like to set two properties in an array's element, but only the last one (p.last_seen_message_text = 'hello'
) has any effect. The first (in this case p.last_seen_message_id = 'e5010536-7fde-42c1-9fea-e4a29e560f53'
) won't change the property.
I use Couchbase 4.5.1-2845 on Windows.
How could I solve this, without using two separate updates?
回答1:
You need a separate FOR for each target.
UPDATE default
USE KEYS '557a7628-1217-4974-95cf-d64247c560cd'
SET p.last_seen_message_id = 'e5010536-7fde-42c1-9fea-e4a29e560f53' FOR p IN participants WHEN p.id = '119c35ab-a1cc-4e9f-bab5-d58d6d396623' END,
p.last_seen_message_text = 'hello' FOR p IN participants WHEN p.id = '119c35ab-a1cc-4e9f-bab5-d58d6d396623' END
WHERE doc_type = 'conversation'
RETURNING default.*;
来源:https://stackoverflow.com/questions/40506203/couchbase-update-for-multiple-set