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

1

17

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

Crook answered 11/6, 2012 at 18:22 Comment(2)
Nano as in the terminal based editor?Rabi
"Nano" as in the couchdb client for Node.js: github.com/dscape/nanoPhonemic
E
31

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

Equanimity answered 11/6, 2012 at 18:31 Comment(1)
How about creating a new view? I assume, just get a design doc, add a view to it, and insert the design doc back in?Sportsman

© 2022 - 2024 — McMap. All rights reserved.