Reputation: 111
I'm relatively new to CouchDB, and am using cradle to interface with it in node.js. I'm trying to include a "count" field in the document, and create an update handler that increments that, so I don't have to do a GET and then a PUT. Currently, I'm defining it as such right after creating the db object:
db.save('_design/main', {
updates: {//Not sure I'm doing this right. Documentation isn't clear to me
updateCount:
function (doc) {
if (!doc.count) {
doc.count = 0;
}
doc.rowImportCount++;
return [doc, JSON.stringify(doc.count)];
}
},
findByFileUuid: {
map: function (doc) {
...view stuff, works perfectly fine...
},
reduce: '_sum'
}
}
Later on in the program, when I try to update count, I do it as such:
db.update('main/updates/updateCount',fileUuid,{},function(res){
console.log(res.message);
});
But it doesn't work. res.message says that "point is undefined".
I'm unable to see what I'm doing wrong and neither the documentation for couchdb or cradle are being very helpful. Note that everything works fine without my count-update attempts.
Thanks!
Upvotes: 1
Views: 307
Reputation: 841
This way worked for me:
db.update('main/updateCount', fileUuid, { rev: doc._rev }, function(res){
console.log(res.message);
});
or
db.update('main/updateCount', fileUuid, { }, function(res){
console.log(res.message);
});
Upvotes: 1