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: [request.query.by,{}],
          endkey: [request.query.by],
          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](http://docs.couchdb.org/en/2.0.0/api/ddoc/rewrites.html#rewrite-section-a-is-stringified-function)
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)?


Regards,

Aurélien

Reply via email to