mcl
mcl

Reputation: 691

CouchDB: Struggling with concept to get data displayed in a web page

As previously advised I have set up a database on iriscouch. Entered a couple of records.

I read in the CouchDB Guide book, I need to create a map function, in order to see my records

eg

function(doc) {
  if(doc.date && doc.title) {
    emit(doc.date, doc.title);
  }
}

Now where do I put this function. Is it a MySQL like view and saved in the database and how do I get the result to my web page ?

Do I create the view within iriscouch somehow ?

Any guidance gratefully received as it is the usual first tentative steps problem of just not getting the idea and I have yet to find a 'Hello World' example which shows all steps.

Thanks

mcl

Upvotes: 2

Views: 388

Answers (1)

JasonSmith
JasonSmith

Reputation: 73722

To me, it is similar as files on a computer filesystem. Most files just store data. But some files are also programs which can run and become an application. In CouchDB, all data is stored in documents however some documents activate special behavior in CouchDB. These are called design documents.

Design documents have an id of _design/example, i.e. it must start with _design/. You can create a document with the Futon tool, just like any other document. Add a key called views with a value of a JSON object:

{ "titles_by_date":
  { "map": "function(doc) { if(doc.date && doc.title) emit(doc.date, doc.title); }"
  }
}

If you have other questions, there is also the Iris Couch forum any discussion about CouchDB and Iris Couch.

Upvotes: 1

Related Questions