You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Aurélien Bénel <au...@utt.fr> on 2017/01/14 17:04:31 UTC

rewrites.js: Format for non-empty `query`

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

Re: rewrites.js: Format for non-empty `query`

Posted by Jan Lehnardt <ja...@apache.org>.
Hi Diana,

this is the Apache CouchDB users mailing list. This has nothing to do with Couchbase.

To unsubscribe, please send an email to user-unsubscribe@couchdb.apache.org <ma...@couchdb.apache.org>

You will have to verify the unsubscription with one more mail and then you’re out, promised :)

Best
Jan
--

> On 18 Jan 2017, at 18:00, Diana Ying <di...@gmail.com> wrote:
> 
> This is the FIFTH email in a row that I've gotten when I tried to
> unsubscribe just now, and it even triggered an email from Rich Bowen. I
> haven't had anything to do with CouchBase for years.
> 
> PLEASE TAKE ME OFF YOUR LISTS completely while you attend to the
> bug...automated or otherwise.
> 
> Thanks,
> Diana
> 
> On Wed, Jan 18, 2017 at 11:53 AM, Michelle Phung <mi...@gmail.com>
> wrote:
> 
>> i am here too. just being quiet -.- sorry :)
>> 
>> - Michelle
>> 
>> On Jan 18, 2017, at 11:12 AM, Aurélien Bénel <au...@utt.fr>
>> wrote:
>> 
>>>> I think the feature is broken when `query` has more than one attribute.
>> (…)
>>>> The ampersand (&) is missing between both query parameters.
>>> 
>>> This is a known bug: https://issues.apache.org/jira/browse/COUCHDB-3171
>>> 
>>> … And I have the strange feeling of talking to myself in a large empty
>> room.
>>> 
>>> 
>>> 
>>> Regards,
>>> 
>>> Aurélien
>> 

-- 
Professional Support for Apache CouchDB:
https://neighbourhood.ie/couchdb-support/


Re: rewrites.js: Format for non-empty `query`

Posted by Diana Ying <di...@gmail.com>.
This is the FIFTH email in a row that I've gotten when I tried to
unsubscribe just now, and it even triggered an email from Rich Bowen. I
haven't had anything to do with CouchBase for years.

PLEASE TAKE ME OFF YOUR LISTS completely while you attend to the
bug...automated or otherwise.

Thanks,
Diana

On Wed, Jan 18, 2017 at 11:53 AM, Michelle Phung <mi...@gmail.com>
wrote:

> i am here too. just being quiet -.- sorry :)
>
> - Michelle
>
> On Jan 18, 2017, at 11:12 AM, Aurélien Bénel <au...@utt.fr>
> wrote:
>
> >> I think the feature is broken when `query` has more than one attribute.
> (…)
> >> The ampersand (&) is missing between both query parameters.
> >
> > This is a known bug: https://issues.apache.org/jira/browse/COUCHDB-3171
> >
> > … And I have the strange feeling of talking to myself in a large empty
> room.
> >
> >
> >
> > Regards,
> >
> > Aurélien
>

Re: rewrites.js: Format for non-empty `query`

Posted by Michelle Phung <mi...@gmail.com>.
i am here too. just being quiet -.- sorry :) 

- Michelle

On Jan 18, 2017, at 11:12 AM, Aurélien Bénel <au...@utt.fr> wrote:

>> I think the feature is broken when `query` has more than one attribute. (…)
>> The ampersand (&) is missing between both query parameters.
> 
> This is a known bug: https://issues.apache.org/jira/browse/COUCHDB-3171
> 
> … And I have the strange feeling of talking to myself in a large empty room.
> 
> 
> 
> Regards,
> 
> Aurélien

Re: rewrites.js: Format for non-empty `query`

Posted by Aurélien Bénel <au...@utt.fr>.
> I think the feature is broken when `query` has more than one attribute. (…)
> The ampersand (&) is missing between both query parameters.

This is a known bug: https://issues.apache.org/jira/browse/COUCHDB-3171

… And I have the strange feeling of talking to myself in a large empty room.



Regards,

Aurélien

Re: rewrites.js: Format for non-empty `query`

Posted by Aurélien Bénel <au...@utt.fr>.
Hi,

>> Has anyone explored the (relatively) new ‘Rewrite using JS’ feature?
> I would still be interested in `rewrites.js` samples. But if anyone have any I will « guess and check » starting from the examples given in the tests.

Well… I think the feature is broken when `query` has more than one attribute.

I tried this very simplified version of my problem.

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

And here are the logs when I query the corresponding URI:

[notice] 2017-01-17T17:40:45.014336Z couchdb@localhost <0.3810.1> efeff7b5a8 127.0.0.1:15984 127.0.0.1 undefined GET /foo/_design/foo/_view/activity?descending=trueinclude_docs=true 400 ok 1

The ampersand (&) is missing between both query parameters.

Any dev out there to confirm or infirm?


Regards,

Aurélien


Re: rewrites.js: Format for non-empty `query`

Posted by Aurélien Bénel <au...@utt.fr>.
Hi folks,

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

No-one? Really?

> The problem is that, for now, I fail figuring out how to format the value of the `query` attribute. (…) 
> 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’ve just found the acceptance tests corresponding to this feature:
    https://github.com/apache/couchdb/blob/master/test/javascript/tests/rewrite_js.js

So, it seems that the documentation is erroneous: the `query` attribute not an array but an object. 
That makes more sense!

I would still be interested in `rewrites.js` samples. But if anyone have any I will « guess and check » starting from the examples given in the tests.


Regards,

Aurélien