derf
derf

Reputation: 411

How to query specific data on couchbase?

If my questions is not appropriate to this forum, please, let me know. I have a question about how to query some specific data using couchbase (using views or not).

This is my problem: I have a lot of records (roughtly 10.000.000), which have codes like this:

01 03 08 14 20 32 40 45 ...

03 07 09 14 28 30 36 42 43 51 ...

03 04 08 10 30 31 48 49 56 63 ...

Those records can have 50 numbers from 01 to 90. None of the numbers repeat inside the record, and there is no repeated records with all same 50 numbers.

What I want is a way to find out very fast, what records have the numbers (for example) 03, 06, 20, 34, 38, 50, 55, 79. The combination can have any sort of numbers (from 01 to 90), with any count of numbers (from 01 to 50).

I know how to do it using mysql, but I'm pretty sure that it can be done using couchbase, I just can't figure out how. Using mysql, I'm spending roughly 20 seconds, and this is not suitable. I need some solution capable of doing this in roughly 2 seconds, or less.

I'm new using couchbase. I really liked this tool and I think it's up to the task. Can someone help me with that?

If this is not the place to this question, please, let me know. And, if possible, please, let me know where I can find the solution.

I'm learning about couchbase, and any help will be welcome. Thank you.

PS.: if you have a more suitable solution to this, please, let me know.

Upvotes: 2

Views: 149

Answers (1)

avsej
avsej

Reputation: 3962

For example you can build view with the only map function like this

function(doc, meta) {
  for (var i = 0; i < doc.codes.length; ++i) {
    emit(doc.codes[i])
  }
}

For example you will store it as _design/test/_view/codes so that you can query it with ?keys=[3,6,20,34,38,50,55,79]

Upvotes: 1

Related Questions