1
votes

My couchdb index return this documents when I query it (this is ok) http://imgur.com/HoBBeSG.

When I want to search index with startkey and endkey, it will only return results based on first field of complex key ignoring the second field. http://imgur.com/QQYx64O.

Does anyone know what the problem is? Thanks.

1

1 Answers

2
votes

This is a common misconception I see with people writing views in CouchDB. When using a complex key like this, the results are sorted by each item in the array in a cascading fashion. (similar to how a SQL database works with multiple SORT BY fields)

Using your example, you should switch the order of your keys as you will only be able to filter from left to right. It is all right to have multiple views that sort/index your data depending on how you want to query it.

I would highly recommend reading the documentation, especially the Guide to Views and about Views Collation since that deals with complex keys.