Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CouchDB create database per document type?

I've just started playing around with couchdb and I'm really liking it so far, but I was wondering when you should be creating a new database.

Here's what I mean:

If i were to create a blog on a server with multiple blogs and this was a RDBMS, I'd create a database called fox_blog and create tables and relations for the posts, comments, etc..

Now in CouchDB, I'd simply make 3 document types: posts, comments and user accounts.

But this is my question: Would I make one db called fox_blog and add a 'type' field to each of the documents (e.g., in the posts documents there would be a 'type' field with the value of 'post')? Or would I make a separate db for each document and precede the name with fox_ (e.g., db name would be fox_posts for the posts)? Or are neither of these correct?

Let me know if any of this is unclear, it was a bit hard to explain heh

like image 987
Obto Avatar asked Jun 13 '11 05:06

Obto


People also ask

How do I create a CouchDB database?

To create a database open the http://127.0.0.1:5984/_utils/. You will get an Overview/index page of CouchDB as shown below. In this page, you can see the list of databases in CouchDB, an option button Create Database on the left hand side. Now click on the create database link.

Does CouchDB have collections?

Couchdb does not have the concept of collections. However, you can achieve similar results using type identifiers on your documents in conjunction with Couchdb views. When you save a document in Couchdb add a field that specifies the type.

Is CouchDB a document database?

Apache CouchDB (CouchDB (link resides outside IBM)) is an open source NoSQL document database that collects and stores data in JSON-based document formats.


1 Answers

You should create a single database with a type field in each document.

You may want to write a view that returns the document and all its comments together.

like image 121
Anand Chitipothu Avatar answered Sep 28 '22 08:09

Anand Chitipothu