huslage
huslage

Reputation: 128

CouchDB list function throwing TypeError (point is undefined)

I am attempting to get a list out of my database. The documents look like:

{
"class": "lists",
"collection": "symptoms",
"order": "6",
"en": "Headache",
"_id": "9022034e7d5ecd0efab0762c5b7f0c04"
}

There are an arbitrary number of "collection"s.

A view function simply returns a bunch of objects in the class "lists":

// Emit lists
exports.viewlist = {
  map: function(doc) {
    if (doc.class === 'lists') {
        emit(
            doc.collection, {
                order: doc.order,
                name: doc.en
            });
    }
  }
};

I wrote a list function to try to filter the output to just the list that I want.

exports.viewlist = function(head, req) {
  var row;
  start({
    code: 200,
    headers: {
        'Content-Type': 'text/json; charset=utf-8',
  }
});
while (row = getRow()) {
    if (row.collection === req.l) {
      send(JSON.stringify(row.value));
    }
  }
};

CouchDB throws an error when I visit the URL of the list:

http://localhost:5984/dev/_design/emr/_list/viewlists/viewlist?l=symptoms

{"error":"TypeError","reason":"{[{<<\"message\">>,<<\"point is undefined\">>},     
{<<\"fileName\">>,<<\"/usr/share/couchdb/server/main.js\">>},  
{<<\"lineNumber\">>,1500},\n  {<<\"stack\">>,
<<\"(\\\"_design/emr\\\",[object Array],
[object Array])@/usr/share/couchdb/server/main.js:1500\
()@/usr/share/couchdb/server/main.js:1562\
@/usr/share/couchdb/server/main.js:1573\
\">>}]}"}

I can't figure out where I'm going wrong here.

Upvotes: 1

Views: 945

Answers (1)

jun
jun

Reputation: 789

I also ran into this error and what causes it, as hinted at by @Pea-pod here Submitting form to couchDB through update handler not working, is not defining properly your exports in the couchapp's design documents. In our case it was as list function that couldn't be called and instead displayed a 500 error with Type error and point is undefined in the couchdb log.

We use kanso and in the app.js we hadn't required the list file. We had:

module.exports = {
    rewrites: require('./rewrites'),
    views: require('./views'),
    shows: require('./shows')
};

Changing it to the following solved the problem:

module.exports = {
    rewrites: require('./rewrites'),
    views: require('./views'),
    shows: require('./shows')
    lists: require('./lists'),
};

Can I suggest to a moderator to change the title of this question to include point is undefined which is the error that shows up in the CouchDB log when this type of error is made, in order to help others find it more easily?

Upvotes: 2

Related Questions