Understanding couchbase

couchdb

We are developing an App which has overall core 15 modules. Whenever a new business is registered either thru mobile or thru web, then we planned to create 15 docs (biz1_users, biz1_loans…etc) which are array type like below. (ref fig 1.0) ex : User Module

Note : There is possibility that a user can have two different business of same type but mobile app has to handle both the biz. Ex : Biz3 and Biz4

User Module : user.json(shema)
{
userProfile :[
{Name : user1, Phone : xxxxxxx },
{Name : user2, Phone : xxxx },…
]
}
Fig 1.0

Is the above approach valid/optimal way. If not what is the best approach?

Couchbase Lite :
How to update a single user using couchbase lite when User object which is an array?
How to verify user registration process from mobile, whether is user already exist or not?
How to sync particular user’s(profile updates) as per the above (fig 1.0) to the server?
How to establish file uploading from mobile during offline and online?
How to handle backup and restore using couchbase lite?
How to handle sync up of single user details updated both web & mobile at single instance?

To have it a scalable model you may have User document with document ID like userProfile::User1 and have data in that document.

This is more like many to many. But we need to think which data size can be higher. It looks like business types will be very few and limited.

So you can put name of all modules in the user profile which user has registered.

If you are using 1.4.1 you can emitt key like [modulename,username] . If you want to get all modules of a user you can get directly by the document id because your app may know the userid.
If you want to know all users by module the your can query on the key emitted above in the view.
If you want to list all users then you will need to emit userid as key.

This is how I would have designed it for scalability. because in the above design what will happen if the user base reach to 50000 then you may have one document having 50000 elements in a collection of json stored. Which can be cumbersome and in efficient to travel in low bandwidth network.

Its more like in nested loop which should be outerloop and which should be inner loop.

If you will be using 2.0 then data extraction is simple with queries.

The document is a MAP of key value pair and array will require looping (even with built in function) to first find out the user and then update values and then again save the complete map.

couch-base user documents which can login into sync gateway doesn’t sync to local. But I think the type of documents we are focusing are not those. So once the data is downloaded you can check by querying a view whether the user already exists or not.

With the design I have given above you can add username as channel in the user profile document. And that user should have access to the channel then the data will sync automatically. And if you dont want to create one login user in sync gateway for every user you have then before the sync starts and after the login you can start sync on the user channel you have put in the documents (e.g.).

See attachment in couchbase lite developer documentation.

Before 5.0 you need to do it using sync gateway rest api.