node.js - Document update error while inserting views dynamically in cloudant couchdb -
i using nosql database(cloudant-couchdb) first time , has been going far. stuck these 2 problems:
i trying add views dynamically. able add first view, errors while trying insert more views stating
document update conflict
. how 'update' since inserting new view everytime , not updating it?is possible pass parameter in map function? -
if(doc.name == somevariable)
?
here code below:
app.put("/listsections", function(req, res) { var module = req.body.name; var obj = {}; obj[module] = { "map": function (doc) { if (doc.name == "developer") { //emit } } }); db.insert({views: obj}, '_design/section', function (error, response) { if (error) { console.log("error: " + error); } console.log("module: " + module ); } );
my approach wrong. found creating multiple views bad practice. created 1 (general) view, , passed queries parameters answer second question (how pass dynamic parameters). here did:
app.get("/listsections", function(req, res) { var moduleid = req.query.id; db.view('section','getsections', { key: moduleid }, function(err, body) { //store values } }
here pass moduleid dynamically map function sets key moduleid. also, found link pretty useful couchdb queries - http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html
Comments
Post a Comment