This page provides a complete reference for PouchDB synchronization options and advanced configuration. For a practical walkthrough with examples, see the Syncing Overview.
Overview
The PouchDB plugin integrates with PouchDB’s replication engine, which provides battle-tested sync capabilities for CouchDB-compatible databases. When you configure the sync option, the plugin automatically sets up bidirectional replication between your local and remote databases.
Sync Configuration Options
remoteDb (Required)
The URL to your remote CouchDB-compatible database. Must be a valid HTTP/HTTPS URL.
Enable continuous synchronization. When true, the sync will continue running and pick up changes in real-time. When false, sync happens once on startup.
Enable automatic retry with exponential backoff. When enabled, failed sync operations automatically retry with increasing delays (1s, 2s, 4s, up to 10s max).
Function to filter documents during sync. The filter function receives a document and returns true to include it or false to exclude it.
>
1
2
3
4
5
6
7
sync:{remoteDb:"http://127.0.0.1:5984/myapp",filter:(doc)=>{// Only sync documents from specific collectionsreturndoc.collectionName==="item"||doc.collectionName==="category";}}
Note: Filters apply to both pull and push unless specified separately in pull or push options.
onChange (Optional)
Callback function that receives sync events. Use this to process synced documents manually, track progress, or handle conflicts.
>
1
2
3
4
5
6
7
8
9
sync:{remoteDb:"http://127.0.0.1:5984/myapp",onChange:(schemas,change)=>{if(change.direction==="pull"&&change.change?.docs){// Process pulled documentsconsole.log(`Pulled ${change.change.docs.length} documents`);}}}
Parameters:
schemas: SchemaCollection - Collection of all schemas in the datastore
change: PouchDB.Replication.SyncResult<{}> - The sync event from PouchDB
PouchDB automatically detects conflicts when the same document is modified in both local and remote databases. Conflicts are indicated by the _conflicts property on documents.
Detecting Conflicts
Check for conflicts in your onChange callback:
>
1
2
3
4
5
6
7
8
9
10
11
12
13
sync:{remoteDb:"http://127.0.0.1:5984/myapp",onChange:(schemas,change)=>{if(change.change?.docs){change.change.docs.forEach((doc)=>{if(doc._conflicts&&doc._conflicts.length>0){console.warn(`Conflict detected in document ${doc._id}`);// Handle conflict: merge, use local, use remote, etc.}});}}}
Resolving Conflicts
You can resolve conflicts by:
Using the local version: Delete the remote conflict revisions
Using the remote version: Delete the local version
Merging: Combine changes from both versions
Using business logic: Apply domain-specific rules to determine the winner
Advanced PouchDB Options
The PouchDB plugin accepts all standard PouchDB replication options. These are passed through to PouchDB’s sync() method. Refer to PouchDB’s replication documentation for the complete list.
Common advanced options include:
doc_ids: Array of document IDs to sync
query_params: Additional query parameters for filtered replication
view: Use a CouchDB view for filtering
since: Sync only changes since a specific sequence number
heartbeat: Interval for heartbeat requests in milliseconds
timeout: Timeout for requests in milliseconds
batch_size: Number of documents to process per batch
batches_limit: Maximum number of batches to process per replication cycle
Sync Patterns
Pull-Only Sync
Use pull-only sync when you want to receive updates from a server but don’t want local changes to sync back: