Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do create couchdb design docs with Nano in Node.js?

Looking through the README it doesn't look there is a way to create design docs with Nano? What are others doing for this?

like image 558
timsavery Avatar asked Jun 11 '12 18:06

timsavery


People also ask

What is Nano in Nodejs?

Nano: The official Apache CouchDB library for Node.js.

What is node CouchDB?

js databases: Using CouchDB. Much like the previous two databases we presented here, CouchDB is an open-source key-value store. But it's also a bit more than that. Each record is not an opaque string: it's a JSON document that the engine understands.


1 Answers

Simply use the db.insert function.

db.insert(design_doc, '_design/design_doc_name', callback);

Here's a more complete example (from tests/view/query):

  db.insert(
  { "views": 
    { "by_name_and_city": 
      { "map": function(doc) { emit([doc.name, doc.city], doc._id); } } 
    }
  }, '_design/people', function (error, response) {
    console.log("yay");
  });

If you are interested in learning some more check this sample or go on and read the CouchDB Guide

like image 160
dscape Avatar answered Sep 19 '22 16:09

dscape