.Net client 1.2.6: Using Views with multiple key values


I have created a development view in Couchbase bucket with data of the following format:

“productId”: “1-124DH9”,
“productCode”: “PCODE”,
“type”: “Example.Product”

The view created is -
function (doc, meta) {
if (doc.type && doc.type == Product’) {
emit([doc.productId], null);

After storing data into the bucket and running this view I get all the data related to this productCrmId.
View result –

{“id”:" Product#1-124DH9",“key”:[“1-124DH9”],“value”:null},
{“id”:" Product#1-12VEXP",“key”:[“1-12VEXP”],“value”:null},


Now my problem is that I want to get this view result in my code filtered by list of keys.

The GetView(designDoc, view, true).Keys<string[]>(new string[] {}) method accepts multiple keys for the same
compound index.

But I have just one key per index, and I cannot find any method using which I can
pass multiple key values and get a list of objects back from the view.

Basically, I want 2 objects returned if I search a view using the following 2 keys - “1-124DH9” and “1-12VEXP”.

Any pointers or suggestions would be great!



Just curious, why do you want to put the key in an 1 value array?

emit(doc.productId, null);

And when you query you can do:


If you really keep the emit in an array - emit([doc.product]); -, you will need to do this key of arrays to get multiple documents:


So in your code you either have to create a list of String or single array String. (from a JSON point of view)


public List Search(Type type, string indexName, List values) where T : class
string[][] newKeys = values.Select(x => new string[] { x }).ToArray();
string jsonValue= JsonConvert.SerializeObject(newKeys);

var result = client.GetView(“dev_Entitlement”, “by_productCrmId”, true).Keys<>();

What type i do need to specify for keys<>(jsonValue) such that i can pass my formatted json value .
Sunil singh

Thanks it is working now updated to emit(doc.productId, null);
sunil singh