Skip to content

Implement multiple Keys search using views #3029

Answered by Terreii
subin94 asked this question in Q&A
Discussion options

You must be logged in to vote

Map views can't be used to search in this way. You would have to create a second view, where key2 and key3 are swapped:

function (doc) { emit([doc.key1, doc.key3, doc.key2, doc.key4], 1) }

Longer answer:

Map/Reduce views are for fast lookup and retrieving of data. To achieve that CouchDB stores your emitted values in a B-Tree, which acts like a list, sorted by their keys.

key1 values key2 values key3 values key4 values
a a a a
a a a b
a a b a
a a b b
a b a a

When you now query with a startkey and endkey, will CouchDB look in that list, where each key would be. And then it will return to you all rows from startkey to endkey and all between them.

With a startkey of ["a", "…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by janl
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants