سؤال

So for my documents, i have a type property that defined them. And almost for all of these 'types', I have to have a 'get by type' call..

Now the question is which one of these design is more efficient;

  • Have a single view that has a key with the 'type' that maps all of the documents

  • Have a view for each 'type' that just maps those types, and I can query the view to get all the documents in the view?

هل كانت مفيدة؟

المحلول

It depends from how many "types" you have in your db. If few - go with "view per type" approach and you'll be fine and have nicer API URLs.

However, when you'll have around 70 types (my case) of documents within single database it would be too oblivious to understand that this approach isn't work anymore and you need one single view to filter docs by type - you'll never forget to add your special view for new doc type, you don't need to cleanup outdated views. As bonus feature, having single view allows you to retrieve docs of multiple types with single request and have only one replication task that syncs multiple types of docs between databases. Same is true for every other fields that are common for a every or most part of docs (like author, updated_at etc.).

Final decision is yours, but better to take the way that will free you from additional work and one additional query parameter is not much higher cost to have relax.

نصائح أخرى

I think the latter is best. Have a view for each type that queries/filters for that particular type. This allows you, from the Futon views drop down, to very quickly display lists of docs of the particular type(s). Almost like you're looking at "tables". But not really ;-)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top