PouchDB ReplicationReplication is a very important feature of PouchDB. It facilitates you to make a copy of a database. You can replicate either a PouchDB instance stored locally or a CouchDB instance stored remotely. While using this method, you can directly pass the location of source and destination databases in String format, or you can pass objects representing them. Syntax Both the source and targets can be either PouchDB instances or CouchDB instances. Replicating PouchDB (Local) to CouchDBLet's take a database named "sample_database" in PouchDB which have 3 documents doc1, doc2, and doc3, having following content. Now create a replication of this database in CouchDB: Save the above code in a file named "Remote_Replication.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output VerificationYou can open CouchDB link and see that a database "sample_database" is created. Image: Replication3 You can also see all three documents here: Replicate CouchDB to PouchDBLet's create a database named "remotedb" on CouchDB server with three documents doc1, doc2, and doc3, having contents as following: Let's replicate this database in local server PouchDB. Save the above code in a file named "Local_Replication.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output: You can verify if the database is replicated in your Pouch instance by using the following code. Save the above code in a file named "Verify_Replication.js" within a folder name "PouchDB_Examples". Open the command prompt and execute the JavaScript file using node: Output Next Topic# |