couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Anderson" <>
Subject Re: How to organize/differentiate Documents?
Date Wed, 16 Jul 2008 15:17:52 GMT
On Wed, Jul 16, 2008 at 7:44 AM, Dean Landolt <> wrote:
>> 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.
> To build on this question a little, many times in a RDBMS setup you Car and
> Truck would end up being three tables, with a Vehicle polymorphic table as
> the base. I get how to distinguish cars vs. trucks, but what about when I
> want to treat them the same, to treat them like Vehicles? I want to see all
> Vehicles, without having to list each one out? I've seen how couch can do
> joins, but it's still not apparent to me how to do inheritance.

Duck typing will go a long way here.

function(doc) {
 if (doc.wheels && doc.engine) {
  //I'm a vehicle
 } else if (doc.wheels && doc.pedals) {
 // I'm a bike

Chris Anderson

View raw message