A type of document that I want to store in couhbase can be queried on various combination of fields.
Should I have multiple views corresponding to each type of query or a single view emitting all the relevant fields across all the queries ?
Views emitting the following keys:
[blah_id, col1]
[blah_id, col2, timestamp]
[blah_id, timestamp]
[blah_id]
V/s
A single view generating the key
[blah_id, col1, col2, timestamp]
( and then using min and max values for columns you don't care about in a particular query )
There are several aspects your should be aware of before making your decision:
Maintainability aspect. When defining single view, I suspect you will have several consumers of that view... what if you need to change that view structure? That means the change will have impact for all existing view consumers. However, if you define into multiple views (one per particular functionality consumer)...changes to one of the views are isolated to other consumers.
Performance aspect. It depends on your data size. If you have one view, you should ask question how many entries it will return vs multiple views. Would that work slower vs multiple (arguably smaller entries wise) views?
So if I were you I'd conduct some sizing and performance testing to select multiple vs single view approach. Personally I'd have favored more multiple views as per consumer maintainability aspect.