0
votes

I would like to know what are the best practices for storing heterogeneous data in CouchDB. In MongoDB you have collections which help with the modelling of the data (IE: Typical usage is one document type per collection). What is the best way to handle this kind of requirement in CouchDB? Tagging of documents with a _type field? Or is there some other method that I am not aware of?

1
To get "collection" behavior in CouchDb, I think that the most "common" way is to include a "meta data" field indicating the type the document represents. This can then be used in your map functions. This is the way I've taken with MyCouch, a lib for .Net. Using $doctype as the field name. I guess you also could have an algorithm for the _id field, with a prefix. Think the first option is cleaner and easier to work with. - Daniel
Seems like a valid way to go. - AshtonKJ
You have an example of it the "the book" as well. There they use "type" guide.couchdb.org/draft/documents.html - Daniel

1 Answers

0
votes

Main benefit of Mongo's collection is that indexes are defined and calculated per collection. In case of Couch you have even more freedom and flexibility to do that. Each index is defined by the view in map/reduce way. You limit the data to calculate the index by filtering it in map function. Because of this flexibility, it is up to you how to distinguish which document belongs to which view.

If you really like the fixed Mongo-like style of division documents into set of distinct partitions with separate indexes just create the field collection and never mix two different collections in single view. In my opinion, rejecting one of the only benefit of Couch over Mongo (where Mougo is in general more powerful and flexible system) does not seem to be good idea.