views:

39

answers:

1

Dears,

i'm looking for implement in my application to have database for the main entity of the system.

i'd like to create and set a database for this entity named with a property value.

Like : For a CMS Project, to create a couchdb database for every Site.

kindly, as that is based on Rest and Rails :

in the create method i have the property value, so i can create the database and save the document in side that database.

but in the other methods how can i specify the database to get the documents from, in (show, edit, update, delete).

and in the index method, how can be enhanced for that scenario (Database per Main Entity).

also, how can i check if there a database with the value i have with creating the database if not exist.

Thanks, Shenouda Bertel

A: 

Hi, you can add a document on the main database per site and use the site name as key (with a prefix, eg. "site_"), for example:

{ _id:"site_sitename",databaseName:"db_sitename",type:"site" }

it's impossible to add two documents with the same _id so you can rest assured that only one site with a given "sitename" exists. to figure out the database, fetch the document through its key, in the example above the document that has the key "site_sitename", and you'll get the name from a property.

From there it's easy to access the documents on that database.

Hope it helps.

cpinto