Try to use view parameter in _changes rest api

59 views
Skip to first unread message

Alex Lai

unread,
Apr 22, 2015, 2:57:51 AM4/22/15
to mobile-c...@googlegroups.com
I try to use view parameter in  _changes rest api. I have set view in database and I have used query to confirm that view works well, but when I use view parameter in _changes rest api, it does not work, it will return all changes, what I want is just return me document which is defined in view. Could some help me?

Alex Lai

unread,
Apr 22, 2015, 3:06:10 AM4/22/15
to mobile-c...@googlegroups.com
What does the "Name of a view function " mean? It is the name of the view?

在 2015年4月22日星期三 UTC+9下午3:57:51,Alex Lai写道:

Jens Alfke

unread,
Apr 22, 2015, 12:15:04 PM4/22/15
to mobile-c...@googlegroups.com

On Apr 21, 2015, at 11:57 PM, Alex Lai <alex...@gmail.com> wrote:

I try to use view parameter in  _changes rest api. I have set view in database and I have used query to confirm that view works well, but when I use view parameter in _changes rest api, it does not work, it will return all changes, what I want is just return me document which is defined in view. Could some help me?

Sorry, that parameter isn’t implemented. :(

(Some of the REST API docs were adapted from CouchDB’s, since our API is based on its. There are a couple of spots where we missed deleting some features that CouchDB supports that we don’t.)

If you want to filter the changes, use the “filter” parameter and define a filter function.

—Jens

Alex Lai

unread,
Apr 23, 2015, 12:04:06 AM4/23/15
to mobile-c...@googlegroups.com
Thank you for your help, I try to use filter and it worked well. : )

在 2015年4月23日星期四 UTC+9上午1:15:04,Jens Alfke写道:

atom992

unread,
Jul 20, 2015, 2:43:08 PM7/20/15
to mobile-c...@googlegroups.com


On Thursday, April 23, 2015 at 12:15:04 AM UTC+8, Jens Alfke wrote:

On Apr 21, 2015, at 11:57 PM, Alex Lai <alex...@gmail.com> wrote:

I try to use view parameter in  _changes rest api. I have set view in database and I have used query to confirm that view works well, but when I use view parameter in _changes rest api, it does not work, it will return all changes, what I want is just return me document which is defined in view. Could some help me?

Sorry, that parameter isn’t implemented. :(
(Some of the REST API docs were adapted from CouchDB’s, since our API is based on its. There are a couple of spots where we missed deleting some features that CouchDB supports that we don’t.)

Hi, I am using couchbaselite-phonegap-plugin 1.1 for android, and when I using REST api to get _changes with filter function and view function,it does't work.  does this mean  that parameter isn’t implemented.?


 

If you want to filter the changes, use the “filter” parameter and define a filter function.

If I use filter=XXX in the _changes request, it return 404,but when I use filters=XXX It return all docs.
 

—Jens

Jens Alfke

unread,
Jul 20, 2015, 3:07:43 PM7/20/15
to mobile-c...@googlegroups.com

On Jul 20, 2015, at 11:43 AM, atom992 <yangzi...@gmail.com> wrote:

Hi, I am using couchbaselite-phonegap-plugin 1.1 for android, and when I using REST api to get _changes with filter function and view function,it does't work.  does this mean  that parameter isn’t implemented.?

Yes, that’s what I said above: the “view=” query parameter isn’t supported.

If I use filter=XXX in the _changes request, it return 404,but when I use filters=XXX It return all docs.

“filters=XXX” will just be ignored because that’s not a known query parameter.

In the REST API you put filter functions in design documents as JS code — specifying “filter=ddoc/foo” will look for a design document named “_design/ddoc”, find a dictionary property named “filters" in it, and look for a string property named “foo” in that.

—Jens

atom992

unread,
Jul 21, 2015, 2:03:40 AM7/21/15
to mobile-c...@googlegroups.com


On Tuesday, July 21, 2015 at 3:07:43 AM UTC+8, Jens Alfke wrote:

On Jul 20, 2015, at 11:43 AM, atom992 <yangzi...@gmail.com> wrote:

Hi, I am using couchbaselite-phonegap-plugin 1.1 for android, and when I using REST api to get _changes with filter function and view function,it does't work.  does this mean  that parameter isn’t implemented.?

Yes, that’s what I said above: the “view=” query parameter isn’t supported.

Is there a roadmap to supported view query parameter?
 

If I use filter=XXX in the _changes request, it return 404,but when I use filters=XXX It return all docs.

“filters=XXX” will just be ignored because that’s not a known query parameter.

In the REST API you put filter functions in design documents as JS code — specifying “filter=ddoc/foo” will look for a design document named “_design/ddoc”, find a dictionary property named “filters" in it, and look for a string property named “foo” in that.

yes I have a filter like this:

{
 
"filters": {
   
"ff": "function (doc, req) {\\\\\\\n                        if(doc.type == \"TYPE1\"){\\\\\\\n                            return true;\\\\\\\n                        }\\\\\\\n                        return false;\\\\\\\n                    }"
 
},
 
"_rev": "1-36cfb89647b0162d1b8e4b504675ce46",
 
"_id": "_design/app"
}


and when I get _changes with filter=app/ff , I got 404. My request is like this:

GET /cbldb/_changes?filter=app/ff HTTP/1.1

and response is like this :

{"status":404}





 

—Jens

Jens Alfke

unread,
Jul 21, 2015, 12:27:32 PM7/21/15
to mobile-c...@googlegroups.com

On Jul 20, 2015, at 11:03 PM, atom992 <yangzi...@gmail.com> wrote:

Is there a roadmap to supported view query parameter?

The REST API is documented at our developer portal, but unfortunately it isn’t 100% in sync with what’s implemented. The docs originated with CouchDB, because that’s what the API is based on, and we’ve mostly updated it to match Couchbase Lite but it’s not perfect yet.

Your filter setup looks correct; this might be a bug in the Android implementation. I’ll ask Hideki to respond.

—Jens

Hideki Itakura

unread,
Jul 21, 2015, 2:43:00 PM7/21/15
to mobile-c...@googlegroups.com
Hi @atom932,

As @jens wrote in previous comment, it seems your codes are correct. 
CBL Android supports _changes with filter parameter. However, Android's  test case does cover _changes with filter parameter. So, our code could have a bug in _changes REST api with filter parameter.

As you received 404 error, some reason CBL Android codes can not find filter function. It could be filter function is not stored in db properly or javascript code is not compiled. 
I wonder to many back-slash (\\\\\\\n) might caused problem. 

I submitted issue ticket for writing unit test case for this scenario. 

Thanks,
Hideki

Jens Alfke

unread,
Jul 21, 2015, 3:03:10 PM7/21/15
to mobile-c...@googlegroups.com

On Jul 21, 2015, at 11:43 AM, Hideki Itakura <hideki....@gmail.com> wrote:

I wonder to many back-slash (\\\\\\\n) might caused problem. 

You’re right, that’s way too many backslashes — a newline in the JavaScript should be written as just “\n” in the JSON. As written, there are a bunch of literal backslashes in the JavaScript code, which are syntax errors.

CBL/Android should be returning a different error code if the JS fails to compile, though. iOS returns 500 "Application callback block failed”. A warning would be good too.

—Jens
Reply all
Reply to author
Forward
0 new messages