Filtered replication with view [startKey and endKey does not work]

41 views
Skip to first unread message

Fábio Pinheiro

unread,
Aug 31, 2016, 7:07:03 PM8/31/16
to PouchDB
Hi,
I have a map reduce (like a join):
function (doc) {
  if (doc.type === "client-user") {
    emit([doc.user, 2], {
      "_id": doc.client
    });
  }
  if (doc.type === "client") {
    emit([doc._id, 1], null);
  }  
}

All database have 30.000 docs, but every user should see about 500 docs. Then I need filter the data in sync to mobile devices (with PouchDB).

Accessing via API, you must inform startKey and endKey for this query works:

https://mydomain.cloudant.com/database/_design/Clients/_view/by_test?startkey=[XXX,1]&endkey=[XXX,2]&include_docs=true


How can I set this view in filter replication and inform startKey and endKey in parameters? I tried this without success, the filter is not applied:

                return remoteDB.replicate.to(localDB, { 

                  filter: '_view',

                  view: 'Clients/by_test',

                  query_params: {"startkey": "XXX", "endkey": "XXX"}

                }).on('complete', function (info) {

                 console.log(‘sync completed’);

                });


thanks a lot!

Fábio



Giovanni P

unread,
Sep 2, 2016, 1:46:51 PM9/2/16
to pou...@googlegroups.com
Filtered replication with view is just a hack to save you the job of writing a filter function. It doesn't accept keys like that, it just runs the doc through the map function and, if the map emits anything, it is considered to have passed the filter.

For fine-grained control like that you must write a custom filter function.

--
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+unsubscribe@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/876e42df-5dd8-46d3-b4e7-e1a056ba481d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages