0

I am new to CouchDB and CouchApp and I am trying to make a couchapp that can be called on any couchdb database and present the user with the available fields so that he can choose one and get all the records for that field.

It would work kind of like this: One calls the app with something like

http://host:5984/couchapp_db/_design/couchapp_name/index.html?host=data_host:5984&db=data_db

This presents the user with the list of keys in the database. The user selects one and the app shows the values for that field.

That requires that there is a view that gets all fields in the database, I already solved that with the post "how could-i-determine-all-possible-keys-of-a-couchdb-database"

In order to get the values the user asks for, I would need a simple view like:

function(doc) {
   if(doc.user_selected_field)
       emit(null, doc.user_selected_field)
}

How can you check from the couch app if this view exists for the database and if it does not, how can you create it?

Maybe there is a pretty standard solution to this, but I have not found it, and, as I mentioned, I am just starting with couchdb.

Community
  • 1
  • 1
Raul
  • 13
  • 3

1 Answers1

0

Couchapp may not be your best option for this. You can use CouchDB on multitudes of way more powerful platforms very easily, so why not consider something else?

CouchApp is a very simple platform for viewing your database, think of it like phpMyAdmin but like really customizable.

citizen conn
  • 15,300
  • 3
  • 58
  • 80
  • Thanks citizen conn, so your recommendation would be to write a server side app, such as a ruby app, that serves the view(and creates it if it does not exist), and query that app from my couchdb application?. – Raul Jul 28 '11 at 17:06
  • you can thank me by upvoting the question or accepting the answer : ) – citizen conn Jul 28 '11 at 17:09
  • sorry, I wanted to keep up the discussion, but pressed enter accidentally – Raul Jul 28 '11 at 17:12
  • Yeah, or just use couchdb as a database and keep the application entirely in ruby. Slideshare is awesome: http://www.slideshare.net/jweiss/couchdb-on-rails – citizen conn Jul 28 '11 at 17:31
  • I want to keep it as a couchapp because I want to visualize the values from the field online using the javascript visualization library protovis. Installing my app as a couchapp saves me from dealing with the same orgin policy, since data and application are both in the couchdb server. – Raul Jul 28 '11 at 17:46
  • Ok, I have been searching a little more. What could work is to request the view (using couchdb's HTTP API) and if the response is an error with the reason 'missing_named_view' then the application posts the view and then gets it. Wouldn't that work? – Raul Jul 29 '11 at 13:56