How to model my domain for using in couchDB?
I'm used to the BigTable nosql db in Google AppEngine. Now I'm learning couchDB with its concept of "document". I'm not sure the two things are the same. In GAE big table you model your data exactly as you would do on a relational db, apart that there are only minimal transaction (usable only to link details to an entity), no joins and no constrain on the fields (every row can have different fields).
Is this true for couchDB as well? are they other ways to map nor开发者_Go百科mal entities? For example for a bug tracker how would you map Bug, User (who opened the bug), Developer (who is supposed to fixed it), BugType and BugStatus?
It has been a while since I used GAE. As far as I remember there are models and all objects of the same model have the same attributes with different values. You are able to query the database with a query language similar to SQL.
In CouchDB everything you store there is a document and you don't have to force your documents into any schema. You query your documents by writing JavaScript functions not by writing SQL and joining tables. Instead you should denormalize your data as much as possible.
I would propose the following example document for a bug:
{
"_id" : "bug-1234",
"type" : "bug",
"state" : "new",
"user" : {
"name" : "user",
"email" : "user@example.com"},
"developer" : {
"name" : "superdev",
"email" : "dev@example.com",
"id" : "dev-123"},
"title" : "this is the bug title",
"description" : "this is the bug description",
"comments" : [
{"user" : "tom", "text" : "first!"},
{"user" : "jerry", "text" : "LOL"}
]
}
This blogpost may help you http://www.couch.io/migrating-to-couchdb
Best blog I found about modelling data in couchdb:
http://www.cmlenz.net/archives/2007/10/couchdb-joins
精彩评论