On 08/02/17 08:23, John Le Brasseur wrote:
Hi.
Can anyone tell me why this works:

{
  "_id": "_design/first_filter",
  "_rev": "24-a6c1822c543f96d1bf4803112092e9ae",
  "filters": {
    "filter1": "function(doc, req) {if (doc.abc === \"xyz\") {return
true;}else{return false;}}"
  },
  "language": "javascript"
}



and this does not:

{
  "_id": "_design/first_filter",
  "_rev": "24-a6c1822c543f96d1bf4803112092e9ae",
  "filters": {
    "filter1": "function(doc, req) {if (doc.def.ghi === \"jkl\") {return
true;}else{return false;}}"
  },
  "language": "javascript"
}


In the second case I get:

[error] 2017-02-07T18:55:40.384000Z couchdb@localhost <0.32487.361>
f201ca664a OS Process Error <0.18298.118> ::
{<<"TypeError">>,{[{<<"message">>,<<"doc.def is undefined">>}

Design documents can be considered by the replication depending on
configuration and the example you have given does not have doc.def.
Perhaps rewrite the test to make sure doc.def is present and is an object.

if(doc.def && typeof doc.def === 'object' && doc.def.ghi === 'jkl'){}
Zynstra is a private limited company registered in England and Wales 
(registered number 07864369). Our registered office and Headquarters are at The 
Innovation Centre, Broad Quay, Bath, BA1 1UD. This email, its contents and any 
attachments are confidential. If you have received this message in error please 
delete it from your system and advise the sender immediately.

Reply via email to