Couchbase update for multiple set

ぃ、小莉子 提交于 2019-12-23 17:19:38

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!