-
Map Function
when I tried when tried with In the given map function, if I need to perform a search using key3 or key4 alone, is it possible ? Any help here is much appreciated 😅 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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.
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", "a", "b"] and endkey of ["a", {}, "b"]
CouchDB returns slices of the list/B-tree. |
Beta Was this translation helpful? Give feedback.
-
I will add a useful analogy: your request would be like asking me to find words in the dictionary whose second letter is an E. Because the typical Webster's (or any other brand of) dictionary isn't ordered according to second-letters, its data structure can't help me with the task. Same way with the index in your example, @subin94 |
Beta Was this translation helpful? Give feedback.
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:
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.
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", "…