0
votes

I'm newbie to Couchbase and trying to understand whether it fits my domain. I have following data:

Birth  City    Name
1980   A       John
1981   B       Rick
1982   A       Ase
1983   C       Max
1984   C       Bob
1980   A       Rick
1983   D       John
1982   A       Bob
1985   C       Bob

And not getting on how to implement similar to following SQL query:

SELECT birth FROM tbl WHERE city in (A,C) and name (Bob, Rick)

to get following data:

1984   C       Bob
1980   A       Rick
1982   A       Bob
1985   C       Bob

One big difference to 'startkey' and 'endkey' view usages is that it's not range selection, it's two different dimension values.

In my real scenario I need to put 1-5000 ID's into 'IN' statement. The only one way I found is to use indexing and N1ql http://docs.couchbase.com/prebuilt/n1ql/n1ql-dp3/#create-index.html but it seems not the fastest way to access data.

  1. What's the best practice to access multi-dimensional key data with lots of keys values?
  2. Is it okay to create big 'in' statements in N1ql?
1
This looks like a query that SQL would be perfect for... any reason why you need to use Couchbase for this? Perhaps ElasticSearch integration would help provide more flexible querying for your needs. - scalabilitysolved

1 Answers

0
votes

You should do a view with the emit function, including a key with two dimension values, and returning the value, in this way:

emit([doc.Name, doc.City], doc.Birth);

And you will have to query it with the param keys:

keys=[["Bob", "A"], ["Bob", "C"], ["Rick", "A"], ["Rick", "C"]]