title: How to manage pouchdb and couchdb synchronization?
body: <p>Best approach to store multiple user data is per user per database. I am using this same approach.</p>
  
  <p>I have couchdb on server and pouchdb for mobile application. I am maintaining each user data by creating separate database for the user in pouchdb and couchdb. That.That means i have multiple database in couchdb and one database in pouchdb.</p>
  
  <p>usually in sqlbase database user data is store in different different table.</p>
  
  <p>so in nosql pouchdb i am creating document for each table.</p>
  
  <p>Actual problem i am facing is:</p>
  
  <p>I have one document in each database that stores the transactions of user.</p>
  
  <p>Client transaction is stored in pouchdb when he/she is offline and when application get on-line transaction sync to couchdb user database in to transaction document.</p>
  
  <p>data is stored in transaction document is as follows</p>
  
  <pre><code>{
    "_id":"transaction ",
    "_rev":"1-3e5e140d50bf6a4d873f0c0f3e3deb8c",
    "data":[
      {
        "transaction_id":"tran_1",
        "transaction_name":"approve item",
        "status":"Pending",
        "ResultMsg":""
      },
      {
        "transaction_id":"tran_2",
        "transaction_name":"approve item",
        "status":"Pending",
        "ResultMsg":""
      }]
  }
  </code></pre>
  
  <p>All these transaction is performed on server side and result is updated in these document.when ever any new transaction performed i store it in transaction document in data attribute.</p>
  
  <p>Now i have 1 transaction in pouch and couchdb both means both are in sync.</p>
  
  <p>Now when mobile application is offline it perform offline transaction that is stored in pouchdb transaction doc.</p>
  
  <p>and on server side that 1 transaction is updated to success.</p>
  
  <p>Now when application goes to on-line and sync perform  i am losing my server side changes and finally data in transaction doc is as client pouchdb.</p>
  
  <p>here i am losing server side data. so what is good approach or how can i solve it.</p>
  
  <p><img src="https://i.stack.imgur.com/wVQAF.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/YHyGj.jpg" alt="enter image description here"></p>