Couchbase Lite Android 1.4中pull.setDocIds()是否可用?
pull.setDocIds() be used in Couchbase Lite Android 1.4? Short answer: No, the setDocIds() method is not supported for pull replications in Couchbase Lite Android 1.4 — this functionality is only available for push replications (which matches your observation that push.setDocIds() works fine).
Why this limitation exists
In Couchbase Lite 1.x, pull replication filtering was designed to rely on custom replication filters rather than direct document ID lists. The setDocIds() method was restricted to push replications because pull sync works by the client requesting changes from the server, and the Sync Gateway (the server-side component for Couchbase Lite sync) in 1.x didn't support server-side filtering by document ID lists for pull requests.
Alternative: Use a replication filter for pull sync
If you need to replicate only specific document IDs via pull in 1.4, you can implement a custom filter that checks each document's ID against your allowed list. Here's how to adjust your code:
List<String> docIDs = new ArrayList<>(); docIDs.add("mensagem"); // Fixed URL typo (http:/ → http://) URL url = new URL("http://" + hostAddress + ":5432/banco144"); final Replication pull = database(EscolherAplicativoActivity.this).createPullReplication(url); // Add a filter to only include documents in your ID list pull.setFilter(new Replication.Filter() { @Override public boolean filter(SavedRevision revision, Map<String, Object> params) { // Check if the current document's ID is in our allowed list return docIDs.contains(revision.getDocId()); } }); pull.start(); pull.addChangeListener(new Replication.ChangeListener() { @Override public void changed(Replication.ChangeEvent event) { // Handle replication state changes here } });
Note: This filter runs locally on the client — the server will still send all changes, but the client will discard any documents that don't match the filter. It's less efficient than server-side filtering, but it's the only way to achieve document ID-based pull filtering in 1.4.
Upgrade for better functionality
If you're able to move to Couchbase Lite 2.x or later, this limitation is removed. Newer versions support using Query objects to define precise replication filters (including document ID lists), which is more efficient and flexible than 1.x's filter system.
内容的提问来源于stack exchange,提问作者Anderson Scherdovski

