igreenfield
igreenfield

Reputation: 1702

Couchbase N1qlQuery: use key value from select

I have this queries:

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

I want to do something like that:

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

but the response I get is:

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

is there a way to do that in one query?

I am using couchbase version 4.5

Upvotes: 1

Views: 1603

Answers (1)

EbenH
EbenH

Reputation: 566

The problem with your query is that the nested subquery returns a json result. I.e., the query:

select otherDocKey from bucket use keys '1234'

will return a result that looks like:

{"otherDocKey":"This_is_the_key_for_the_other_doc"}

But you don't want json, you just want the value from the json. For that you need to use 'select raw'. E.g.,

select raw otherDocKey from bucket use keys '1234'

That should give you a result that looks like:

["This_is_the_key_for_the_other_doc"]

When the subquery returns that kind of result, the "use keys" should work properly.

Upvotes: 2

Related Questions