2016-11-28 20 views
1

鍵值我有這樣的疑問:Couchbase N1qlQuery:使用來自選擇

select otherDocKey from bucket use keys '1234' 
update bucket use keys 'hear I need the result of the first query' set ... 

我想要做這樣的事情:

update bucket use keys (select otherDocKey from bucket use keys '1234') set kuku = 3 

,但我得到的迴應是:

[ { "code": 5030, "msg": "Missing or invalid primary key map[otherDocKey:\"56443\"] of type map[string]interface {}." } ]

有沒有辦法在一個查詢中做到這一點?

我使用couchbase 4.5版

+0

[這](http://stackoverflow.com/questions/31298550/using-n1ql-with-document-keys)看起來非常接近你需要的東西 – summerbulb

+0

@summerbulb這是選擇加入它不同。我無法加入更新。 – igreen

回答

1

的問題,您的查詢是嵌套子查詢返回JSON結果。即,查詢:

select otherDocKey from bucket use keys '1234'

會返回一個結果,看起來像:

{"otherDocKey":"This_is_the_key_for_the_other_doc"} 

但是你不想JSON,你只是想從JSON值。爲此你需要使用'select raw'。例如,

select raw otherDocKey from bucket use keys '1234' 

這應該給你一個結果,看起來像:

["This_is_the_key_for_the_other_doc"] 

當子查詢返回樣的結果,「用鍵」即可正常使用。