You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Jeroen van Dijk <je...@gmail.com> on 2011/08/08 13:32:56 UTC
How to use the changes feed with a view as filter
I've tried to run the changes feed on a specific view, but so far I haven't succeeded. I'm only able to use the 'doc_ids' filter, but I can't filter using a view.
I've tried the following requests (using IrisCouch, couchdb version 1.1):
GET http://myaccount.iriscouch.com/mydb/_changes?filter=_doc_ids&doc_ids=["_design/mydb/_view/my_view]
GET http://myaccount.iriscouch.com/mydb/_changes?filter=_design&design=_design/mydb/_view/my_view
Both give me the same result whereas I would expect the 'filter=_design' to give me the result of the map function and not the changes of the design document itself. The second request also works without the design parameter:
GET http://myaccount.iriscouch.com/mydb/_changes?filter=_design
I think that also indicates I am doing something wrong. Anyone knows how to get this working?
Thanks,
Jeroen
NB. My Erlang is not good enough to understand what exactly happens here: https://svn.apache.org/repos/asf/couchdb/tags/1.1.0/src/couchdb/couch_changes.erl
RE: How to use the changes feed with a view as filter
Posted by Hong-Thai Nguyen <Ho...@polyspot.com>.
Hi,
I'm looking for the same solution. The main raison of using view filter in _changes is to accelerate find out the appropriate modified data (filter in _changes not have index, so too slow in large-scale scenario).
I suppose that, our database has 1M documents, I've just deleted 1 document, and I'd retrieval this latest modif without scan previous 1M docs (I don't know which _lastseq value to pass through ?since= param).
Do you have any suggestion for this problem ? Jan was totally right, view filter doesn't not raise up deleted documents, so no sense in this case.
Special thanks
------------------------
Hong-Thai
-----Original Message-----
From: Jens Alfke [mailto:jens@couchbase.com]
Sent: lundi 8 août 2011 20:14
To: user@couchdb.apache.org
Subject: Re: How to use the changes feed with a view as filter
On Aug 8, 2011, at 5:43 AM, Jeroen van Dijk wrote:
This is the original thread that gave me the impression it should be
possible: http://comments.gmane.org/gmane.comp.db.couchdb.user/13364
According to that thread (and the commit message) this is just a shortcut to avoid having to write a filter function that duplicates an existing map function.
Jan wrote "This so you can get a notification for when a view *would* be updated if you queried it.", but I don't see how that follows. Sure, it will tell you when a new revision of a document will appear in the view, but it won't tell you when a document that used to be in the view isn't any more (because the filter function no longer emitted any rows for it). Being notified of only insertions and updates but not deletions doesn't seem useful in practice.
-Jens
Re: How to use the changes feed with a view as filter
Posted by Jens Alfke <je...@couchbase.com>.
On Aug 8, 2011, at 5:43 AM, Jeroen van Dijk wrote:
This is the original thread that gave me the impression it should be
possible: http://comments.gmane.org/gmane.comp.db.couchdb.user/13364
According to that thread (and the commit message) this is just a shortcut to avoid having to write a filter function that duplicates an existing map function.
Jan wrote "This so you can get a notification for when a view *would* be updated if you queried it.”, but I don’t see how that follows. Sure, it will tell you when a new revision of a document will appear in the view, but it won’t tell you when a document that used to be in the view isn’t any more (because the filter function no longer emitted any rows for it). Being notified of only insertions and updates but not deletions doesn’t seem useful in practice.
—Jens
Re: How to use the changes feed with a view as filter
Posted by Jeroen van Dijk <je...@gmail.com>.
On Mon, Aug 8, 2011 at 2:17 PM, Sean Copenhaver
<se...@gmail.com>wrote:
> Oh wow, I was unaware that you could filter by view. The code indeed makes
> it look that way. I'm not sure which release this was done in though, or if
> you would need to build from latest source.
>
> Anyway, the code makes me think the request would be more like this:
> GET
>
> http://myaccount.iriscouch.com/mydb/_change?filter=_view&view=_design/mydb/_view/my_view
>
>
Actually the following seems to be more of what I want, but apparently I'm
not calling it correctly:
GET
http://myaccount.iriscouch.com/mydb/_changes?filter=view&view=myview/my_view
=> {"error":"bad_request","reason":"filter parameter must be of the form
`designname/filtername`"}
> I get that from here:
>
> https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_changes.erl#L144
>
> Looks like those function clauses are to define the different built in
> filters plus the last one to catch custom ones. The one on that line looks
> like what you are after and it's expecting a 'view' query string parameter
> I
> think.
>
> I believe the _design filter is to monitor for when a design document
> changes and not to filter by a function inside of it. I don't have anything
> setup to test this though.
>
I think you are right.
>
> Hopefully someone with not knowledge is able to confirm this and which
> release this was in
>
Yes please. I think it is a 1.1 feature, but maybe you can only filter on
doc ids and design docs:
https://github.com/apache/couchdb/blob/trunk/CHANGES#L63
This is the original thread that gave me the impression it should be
possible: http://comments.gmane.org/gmane.comp.db.couchdb.user/13364
On Mon, Aug 8, 2011 at 7:32 AM, Jeroen van Dijk
> <je...@gmail.com>wrote:
>
> > I've tried to run the changes feed on a specific view, but so far I
> haven't
> > succeeded. I'm only able to use the 'doc_ids' filter, but I can't filter
> > using a view.
> >
> > I've tried the following requests (using IrisCouch, couchdb version 1.1):
> >
> > GET
> > http://myaccount.iriscouch.com/mydb/_changes?filter=_doc_ids&doc_ids=[
> > "_design/mydb/_view/my_view]
> > GET
> >
> http://myaccount.iriscouch.com/mydb/_changes?filter=_design&design=_design/mydb/_view/my_view
> >
> > Both give me the same result whereas I would expect the 'filter=_design'
> > to give me the result of the map function and not the changes of the
> design
> > document itself. The second request also works without the design
> parameter:
> >
> > GET http://myaccount.iriscouch.com/mydb/_changes?filter=_design
> >
> > I think that also indicates I am doing something wrong. Anyone knows how
> to
> > get this working?
> >
> > Thanks,
> >
> > Jeroen
> >
> >
> > NB. My Erlang is not good enough to understand what exactly happens here:
> >
> https://svn.apache.org/repos/asf/couchdb/tags/1.1.0/src/couchdb/couch_changes.erl
>
>
>
>
> --
> “The limits of language are the limits of one's world. “ -Ludwig von
> Wittgenstein
>
Re: How to use the changes feed with a view as filter
Posted by Sean Copenhaver <se...@gmail.com>.
Oh wow, I was unaware that you could filter by view. The code indeed makes
it look that way. I'm not sure which release this was done in though, or if
you would need to build from latest source.
Anyway, the code makes me think the request would be more like this:
GET
http://myaccount.iriscouch.com/mydb/_change?filter=_view&view=_design/mydb/_view/my_view
I get that from here:
https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_changes.erl#L144
Looks like those function clauses are to define the different built in
filters plus the last one to catch custom ones. The one on that line looks
like what you are after and it's expecting a 'view' query string parameter I
think.
I believe the _design filter is to monitor for when a design document
changes and not to filter by a function inside of it. I don't have anything
setup to test this though.
Hopefully someone with not knowledge is able to confirm this and which
release this was in.
On Mon, Aug 8, 2011 at 7:32 AM, Jeroen van Dijk
<je...@gmail.com>wrote:
> I've tried to run the changes feed on a specific view, but so far I haven't
> succeeded. I'm only able to use the 'doc_ids' filter, but I can't filter
> using a view.
>
> I've tried the following requests (using IrisCouch, couchdb version 1.1):
>
> GET
> http://myaccount.iriscouch.com/mydb/_changes?filter=_doc_ids&doc_ids=[
> "_design/mydb/_view/my_view]
> GET
> http://myaccount.iriscouch.com/mydb/_changes?filter=_design&design=_design/mydb/_view/my_view
>
> Both give me the same result whereas I would expect the 'filter=_design'
> to give me the result of the map function and not the changes of the design
> document itself. The second request also works without the design parameter:
>
> GET http://myaccount.iriscouch.com/mydb/_changes?filter=_design
>
> I think that also indicates I am doing something wrong. Anyone knows how to
> get this working?
>
> Thanks,
>
> Jeroen
>
>
> NB. My Erlang is not good enough to understand what exactly happens here:
> https://svn.apache.org/repos/asf/couchdb/tags/1.1.0/src/couchdb/couch_changes.erl
--
“The limits of language are the limits of one's world. “ -Ludwig von
Wittgenstein