couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Lehnardt <>
Subject Re: How to organize/differentiate Documents?
Date Wed, 16 Jul 2008 09:06:55 GMT

On 16 Jul 2008, at 07:02, Troy Kruthoff wrote:

> Surprise :)  There is no established type declarations in couchdb.   
> Once you get used to it, it is very liberating to work outside the  
> confines of an established type system.  Big hint, the separate db  
> approach is not where you want to go.  But you are on track with  
> using a 'type' attribute.  I have also used views for more simpler  
> schemas, such as a simple contact database might have views for  
> 'contacts/people' and 'contacts/companies' based on something like  
> "if (doc.company_name) //I'm a company" and "if (doc.first_name ||  
> doc.last_name) //I'm a person"

Thanks Troy, this is all good advice.

I'll add one more bit. CouchDB will have insert / update validation.  
That will be just another JavaScript function that allows or declines  
the insertion or change of a document based on criteria you put into  
that function. This will give you some schema enforcement  
capabilities. But even with that, documents are meant to be ad-hoc in  


> On Jul 15, 2008, at 9:39 PM, Avi Flax wrote:
>> Hi, I'm new to couchdb, and I apologize if this is a FAQ, but I  
>> can't seem
>> to find what I'm looking for anywhere.
>> I'm trying to understand the intended usage pattern for  
>> applications using
>> couchdb as a data store. Specifically, I'm wondering what the  
>> intended
>> approach to differentiating between different types of documents are.
>> For example, if my application has two entities: Cars and Trucks,  
>> in a RDBMS
>> I'd create two different tables; one to store Cards and one to  
>> store Trucks.
>> If I wanted cars I'd run a query on the "cars" table; if I wanted  
>> trucks I'd
>> run a query on the "trucks" table.
>> I'm a little unclear on how to achieve a similar use case with  
>> couchdb. I
>> guess I could create separate databases for Cars and Trucks, but that
>> doesn't seem right; I'm dubious that the designers intended  
>> databases to be
>> used like tables. In searching the mailing list I saw that some  
>> documents
>> had a field named "type". That seems like a good way to differentiate
>> document types; my hesitation there is that it just seems very ad- 
>> hoc; I'd
>> be surprised if there's no more firmly established method for  
>> distinguishing
>> between document types.
>> Apologize if this doesn't make much sense, I'm up later than I  
>> should be.
>> Thanks!
>> -- 
>> Avi Flax » Lead Technologist » Partner » Arc90 »

View raw message