1

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!

Peter Somers
  • 111
  • 4
  • I am not sure about cradle, but the updates section looks fine, if the update cmd does a put, then your url would be '_design/main/_update/updateCount/' ex `db.update('_design/main/_update/updateCount' + fileUuid, ...) ` – twilson63 Mar 04 '15 at 12:37
  • Oh, okay. I will take a look. I ended up deciding to do the progress tracking in the program and then just update a variable in couchdb every x percent, skirting the issue. Thanks anyway though! – Peter Somers Mar 04 '15 at 14:32

1 Answers1

1

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);
});
Brankodd
  • 831
  • 9
  • 21
  • Okay, thanks for the help! I ended up doing something that doesn't require a counter, but if I need it I will definitely take a look! – Peter Somers Mar 09 '15 at 17:31