couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aurélien Bénel <>
Subject rewrites.js: Format for non-empty `query`
Date Sat, 14 Jan 2017 17:04:31 GMT
Good evening,

Has anyone explored the (relatively) new ‘Rewrite using JS’ feature?

To begin with, I would like to thank developers for this very interesting feature.
The problem is that, for now, I fail figuring out how to format the value of the `query` attribute.

In the ancient `rewrites.json` file, one of my rule was:

        "method": "GET",
        "from": "",
        "to": "_list/activity/activity",
        "query": {
          "descending": "true",
          "startkey": [":by",{}],
          "endkey": [":by"],
          "include_docs": "true"

In my new `return.js` file, I thought the corresponding return value would be:

    return {
       path: "_list/activity/activity",
       query: {
          descending: true,
          startkey: [,{}],
          endkey: [],
          include_docs: true

Because it didn’t work at all (error 500), I simplified the problem into:

    return {
      path: "_view/activity",
      query: {
        "descending": true,
        "include_docs": true

But I got:

    {"error":"rewrite_error","reason":"object key/value must be strings <<\"descending\">>=true"}

When I changed `true` (boolean) into `"true"` (string), I got:

    {"error":"query_parse_error","reason":"Invalid boolean parameter: \"trueinclude_docs=true\""}

Then I reread the [corresponding documentation](
and discovered that `query`was supposed to be an array. But nothing was written about how
the array was supposed to be formatted.

I tried (but without heart):

    return {
      path: "_view/activity",
      query: ['descending="true"','include_docs="true"']

And got:

    {"error":"rewrite_error","reason":"bad query"}

Any idea (or any other documentation)?


View raw message