Best approach to store multiple user data is per user per database. I am using this same approach.
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.
usually in sqlbase database user data is store in different different table.
so in nosql pouchdb i am creating document for each table.
Actual problem i am facing is:
I have one document in each database that stores the transactions of user.
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.
data is stored in transaction document is as follows
{
"_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":""
}]
}
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.
Now i have 1 transaction in pouch and couchdb both means both are in sync.
Now when mobile application is offline it perform offline transaction that is stored in pouchdb transaction doc.
and on server side that 1 transaction is updated to success.
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.
here i am losing server side data. so what is good approach or how can i solve it.