You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replication Filters allow you to have quick control over the documents stored as the result of a push and/or pull replication.
420
+
421
+
##### Push Filter
422
+
423
+
The push filter allows an app to push a subset of a database to the server. This can be very useful. For instance, high-priority documents could be pushed first, or documents in a "draft" state could be skipped.
"show source"; // directive needed to persist function body as string
434
+
435
+
if (document?.["type"] ==="draft") {
436
+
returnfalse;
437
+
}
438
+
returntrue;
439
+
});
440
+
441
+
config.addCollection(collection, colConfig);
442
+
443
+
const replicator =awaitReplicator.create(config);
444
+
awaitreplicator.start();
445
+
```
446
+
447
+
1. The callback should follow the semantics of a [pure function](https://en.wikipedia.org/wiki/Pure_function). Otherwise, long running functions would slow down the replicator considerably.
448
+
449
+
##### Pull Filter
450
+
451
+
The pull filter gives an app the ability to validate documents being pulled, and skip ones that fail. This is an important security mechanism in a peer-to-peer topology with peers that are not fully trusted.
452
+
453
+
:::note
454
+
Pull replication filters are not a substitute for [channels](https://docs.couchbase.com/sync-gateway/current/channels.html). Sync Gateway channels are designed to be scalable (documents are filtered on the server) whereas a pull replication filter is applied to a document once it has been downloaded.
"show source"; // directive needed to persist function body as string
466
+
467
+
if (flags.includes(ReplicatedDocumentFlag.DELETED)) {
468
+
returnfalse;
469
+
}
470
+
returntrue;
471
+
});
472
+
473
+
config.addCollection(collection, colConfig);
474
+
475
+
const replicator =awaitReplicator.create(config);
476
+
awaitreplicator.start();
477
+
```
478
+
479
+
1. The callback should follow the semantics of a [pure function](https://en.wikipedia.org/wiki/Pure_function). Otherwise, long running functions would slow down the replicator considerably.
480
+
481
+
:::caution
482
+
For now, pull filters can handle up to 100 documents per replication. If you exceed this number, the replicator may freeze. This will be fixed in the next version.
483
+
:::
484
+
485
+
:::info Losing access to a document via the Sync Function
486
+
487
+
Losing access to a document (via the Sync Function) also triggers the pull replication filter.
488
+
489
+
Filtering out such an event would retain the document locally.
490
+
491
+
As a result, there would be a local copy of the document disjointed from the one that resides on Couchbase Server.
492
+
493
+
Further updates to the document stored on Couchbase Server would not be received in pull replications and further local edits could be pushed but the updated versions will not be visible.
494
+
:::
495
+
417
496
### Channels
418
497
419
498
By default, Couchbase Lite gets all the channels to which the configured user account has access.
0 commit comments