Search code examples
couchdbcradle

How to get a CouchDB _list result with Cradle


In Node, using Express and Cradle, I have a call to a _list that does not work. Other calls go to _view and work fine. The Cradle documentation does not include a section on _list but it seems from this GitHub readme that it is supposed to work just like _view.

My code looks like:

if(isList){
    db.list(couch_url, function (err, res) {
        if(err){
            console.log("error couchdb list", err);
        }else{
            //console.log(res);
            callback(JSON.stringify(res));
        }
    });     
}

The couch_url variable is just the regular http request and looks like: myCouch/_design/Model3D/_list/convert/All except the path designators (_design, _view, _list) have been removed to get Model3D/convert/All for Cradle (it looks like they are put back in the Cradle function). That full path represented by couch_url will work in other CouchDB connections, and like I said, the Cradle view function works fine.

The error object I get is:

{ stack: [Getter/Setter],
    arguments: [ 'ILLEGAL' ],
    type: 'unexpected_token',
    message: [Getter/Setter] }

Solution

  • Check the list function you are using - it is highly likely to be producing broken JSON. In my case, I was getting a result of 'undefined' for a property. Anything undefined should be dropped, and all property names should be in quotes