1
votes

I use couchbase service to store temporary information. Here is my problem: I have many pairs of key-value, but they are, however, conventionally divided into groups (key1_ *; key2_ *; key3_ *). For example the pair would looks like:

"key1_1":"value1"; "key1_2":"value2"; "key1_3":"value3";
"key2_1":"value4"; "key2_2":"value5"; "key2_3":"value6";
"key3_1":"value7"; "key3_2":"value8"; "key3_3":"value9";

I need to send an request that will be used to return information about the availability of values ​​for any of these groups: for example:

var info = client.Get ("key1_ *") or something like that. Is there any filter in the names of keys, or are any options for grouping, which could solve my problem?

1

1 Answers

1
votes

In couchbase 2.0 you can use Views. You can store json object in database, so key-val pair should look like:

key:<guid>; value: {id:<guid>, group<int>, data<your_values_type>}

Where group is an equivalent to key1_*; Then create a view with Map:

function (doc) {
  emit(doc.group, [doc.id, doc.group, doc.data]);
}

You've get key-value pairs of such format:

key: <int>group ; value: <array>[id,group,data]

then you can filter results by key by adding "?key=" to request. Or if you use some api libs, i.e. .net api, you can do it from your code:

Client.GetView<Int64>(Couchbase.Configuration.DevelopmentModeNameTransformer.NamePrefix + "MyViewName", "MyViewName").Key(<desired_key>)