Corey
Corey

Reputation: 486

How to create N1QL query with array parameter couchbase sdk 3.0

I want to create a parameterized query in which one of the parameters is an array/list. For example:

var query = @"
SELECT
         doctype1.user_id
FROM     bucket doctype1
JOIN     bucket doctype2
ON       doctype2.user_id = doctype1.user_id
AND      doctype2.type = ‘doctype2’
AND      doctype2.value.Value IN [$myset]
WHERE    doctype1.type = ‘doctype1’
AND      doctype1.value.Type = $type
ORDER BY doctype1.user_id
LIMIT 2
OFFSET 0";

I've tried things like doing:

None of which are working

Upvotes: 1

Views: 414

Answers (1)

Corey
Corey

Reputation: 486

I feel a bit dense but this was the solution for anyone else running into this issue:

I changed my initial string query and removed the square brackets to look like this:

AND doctype2.value.Value IN $myset

Then I was able to use either

  • $myset = new List() { "val1", "val2" }
  • $myset = new[] { "val1", "val2" }

Hope this helps someone else!

Upvotes: 2

Related Questions