Search code examples
javascriptcouchdbcouchdb-nano

does not eval to a function error in couch db


I'm using Couchdb 1.6.1. I have a show inside test design.

{
   "select": {
       "map": "function(a){emit(null,a._id)}"
   }
}

i'm using Nano Node modules to interact with the database. When i run js file below this { Error: Expression does not eval to a function. ([object Object]) error message is returned.

this.database.show('test', 'select', 35435156453, function (error, body) {
  if(error) {
      console.log(error);
  }
  else{
      console.log(body);
  }
});

I tried wrapping up the function with parentheses like below. That didn't work

{
   "select": {
       "map": "(function(a){emit(null,a._id)})"
   }
}

Why I'm getting this error?


Solution

  • So first of all, you are using a show function as if it were a view function (which is completely different).

    If you really want to use a show "function", then I suggest you get a look into this documentation. Show function are used to return data as HTML or with any formatting your require. You normally define a show function like this:

    {
        "select":"function(doc,req){return 'Return your stuff here.'}"
    }
    

    The function you provided us is a mapping function which is used in views. See this link for further documentation. If it's the case, you would only need to use this.database.view() I guess.