how to filter the changes feed dynamically

278 views
Skip to first unread message

Alexander Gabriel

unread,
Feb 8, 2015, 6:53:05 PM2/8/15
to pou...@googlegroups.com
in couchdb it is possible to filter a changes feed dynamically by passing an argument named request. See: http://docs.couchdb.org/en/latest/couchapp/ddocs.html#filter-functions
In this exaple a status can be passed:

GET /somedatabase/_changes?filter=mailbox/by_status&status=new HTTP/1.1

My use case: I want to filter only the users documents. So I need to pass the username.

I haven't found anything about this in the docs.

Is it possible?

Nolan Lawson

unread,
Feb 9, 2015, 8:43:30 AM2/9/15
to pou...@googlegroups.com
If you are trying to restrict users from reading each other's documents, you're probably going to want to go for the "db per user" approach (see the pouchdb-authentication readme). Another benefit is that you don't need filter functions.

In order to make your scenario work with filter functions, you would need to manually attach a username to every document stored in the database. And add a validate_doc_update function to ensure that users only write documents with their own username. A lot of headaches you can avoid by just doing "db per user" :).

Alexander Gabriel

unread,
Feb 9, 2015, 9:18:31 AM2/9/15
to pou...@googlegroups.com
It may well be that I am missing something but I believe a database per user is not the optimal solution for the app I'm working on.

Main reason: Users will be working together on projects and sharing lots of documents and attachments. Some of the attachments will be large (pixel basemaps for offline mapping). If 5 people work together in a project with a database per user that's five times the data on the server. And it's lots of syncing.

Plus rcouch'es view changes & view based replication are coming (soon?) in couchdb 2.0. I'm hoping couchdb 2.0 will be ready by the time my new app is ready (a few months). Otherwise I will use rcouch on the server (I develop on windows and rcouch doesn't run on windows).

This app is not going to have more than a few hundred or thousand users so I'm not bothered by the limitations of scaling filtered replication.

Yes, every document has a list of users which work with it.

So it would be nice if, until view changes & view based replication have arrived, I could filter the changes stream dynamically like in couchdb.


--
You received this message because you are subscribed to the Google Groups "PouchDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pouchdb+u...@googlegroups.com.
To post to this group, send email to pou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pouchdb/58bf6e2e-015a-448e-be35-50a3156e9458%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nolan Lawson

unread,
Feb 10, 2015, 11:11:29 AM2/10/15
to pou...@googlegroups.com
In that case, could you do a "role per group" model, where each user can have multiple roles, and each role has its own database?

As for view changes and view-based replication, such a thing may (eventually) exist in CouchDB, but it has not been implemented for PouchDB yet.

But if you really, really want filtered replication, then yes: you can do it in PouchDB/CouchDB. You just need to reference a design document that exists in CouchDB, exactly as you have it in your first message. The API does mention that "filter" is supported: http://pouchdb.com/api.html#changes

- Nolan

Alexander Gabriel

unread,
Feb 10, 2015, 2:07:29 PM2/10/15
to pou...@googlegroups.com

role per group, database per role?
sounds good
will give it a go
great help
thanks!

--
You received this message because you are subscribed to the Google Groups "PouchDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pouchdb+u...@googlegroups.com.
To post to this group, send email to pou...@googlegroups.com.

Alexander Gabriel

unread,
Feb 12, 2015, 5:47:23 AM2/12/15
to pou...@googlegroups.com
nice, it works

Reply all
Reply to author
Forward
0 new messages