incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Davis" <>
Subject Re: newbie question #1
Date Sun, 28 Dec 2008 13:26:30 GMT
On Sun, Dec 28, 2008 at 8:12 AM, Geir Magnusson Jr. <> wrote:
> I work for a company (10gen) that's making what I refer to as a "document
> oriented" database (called MongoDB*), and I've long been meaning to grok
> CouchDB.  Now that I have some time during the year-end hibernation, I
> figured this is a good time to dig in.
> So I have some basic questions.  Warning - these are really basic, and could
> be caused entirely by my current lack of caffination.  I assume the best
> place to find docs is the wiki.  If there's something better, any pointers
> welcome.

Also check out for related blog posts. I
also find a google alert for CouchDB to be pretty useful.

> First newbie question :
> Looking at, I understand
> that _id and _rev are reserved fields in the document**.  Now, looking at
> the _all_docs example, I see I get back a list of docs :
> {
>  "total_rows": 3, "offset": 0, "rows": [
>    {"id": "doc1", "key": "doc1", "value": {"rev": "4324BB"}},
>    {"id": "doc2", "key": "doc2", "value": {"rev":"2441HF"}},
>    {"id": "doc3", "key": "doc3", "value": {"rev":"74EC24"}}
>  ]
> }
> what is "id"?  is that supposed to be "_id"?  what is "key"?  I see that in
> futon as well - how does it relate to "_id" or "id" for that matter?  Also,
> I assume that "rev" is the "_rev" of the document.  Why not make it "_rev"?
> I'm guessing that "id" is "_id", as I can see similar things in the PUT
> example, but I guess then the question changes to why not just be consistent
> and use "_id" everywhere, especially since I'm allowed to use "id" in my
> document?
> I'm sorry if this is a stupid question - I just don't understand.  I'm happy
> to update the wiki when I understand :)

You're pretty much spot on here. "id" and "key" both refer to the
"_id" field in a document. And the "rev" does indeed refer to the
"_rev" attribute. Why "id" and "rev" are used instead of "_id" and
"_rev" I couldn't really tell you. I hate to say "historical reasons"
but I'm guessing that when Damien designed the view output he just
labeled then "id" and "rev" without the underscore because it's not
needed to distinguish from the rest of the doc.

> geir
> I put these notes at the bottom as they are asides...
> * MongoDB - I'm getting a "community" site going (
> indep of our corp site (  It's open source, written
> in C, and has some very nice features.
> ** I've had this debate internally at 10gen too, and I'm not interested in
> picking a fight here :)  I think that by reserving fields like this, you
> can't claim to be storing JSON anymore, but "JSON--" or "almost JSON".   I
> think that a better way to do this is provide a JSON-based "envelope" for
> documents in which the database reserves all fields, and the user document
> is "hung" in there on one of them.  This allows adding metadata over time
> free of collision with the user documents :
>  {
>     _id : whatever
>     _rev : whatever
>     doc : { ..... the full user document that can have _id, _rev and
> whatever....}
>  }

Like Noah says, reserving underscore prefixed fields as private to
CouchDB doesn't make it not JSON. I'd argue that putting the document
stuff inside a doc member would probably be a annoyance in that every
operation on the doc would require instead of just

Paul Davis

View raw message