CouchDB / PouchDB best practice

Hi this is not really an IONIC question, but the the goal is still to create an app with IONIC.

So I want to create an app to manage buildings. An user can hold multiple buildings.
Each building has rooms. Each rooms has logs. Each user is a member of an cooperation.

So for many years I’ve used LAMP. Now moving to mobile and made some IONIC apps.
With 2 apps I’ve used sqlLite as datastore on the mobile device.

But now I’ve read up on couchDB and pouchDB and really like the concept and the sync option.
So now I’m looking into this to use as my datastore (on the mobile and also on the backend).

Now I’ve got 3 major questions/concerns:

  1. Authentication

So in my LAMP situation, I usualy have an SESSION (table wich holds the sessions strings and userID) and an USERS table.
When the user logs in, the user is lookup in the USERS table, and a session string is created and saved with the userID.

So now each time a request is made to the server (for example update data), the session string is also supplied and matched to the SESSION table and retrieve the correct user.
So from that point on, I can validate if the post is valid and the data also belongs to the correct user.

Back to couchDB. So I know there is a cookie management in couchDB (
So here I can validate if an user exists and validate the credentials. Now the app can send requests with a cookie.

  1. Fetch/Update the right data
    In my LAMP situation, I always knew, wich data belongs to wich user. And the backend always checks if this is correct.

In my couchDB I want to create database and each document is an user with all the data.
So now here comes the problem. I can validate an user in couchDB, put there’s no way to validate the data (at least as far I know of) that it belongs to the right user.
My goal is that the mobile device syncs the document to the couchDB server.

  1. Database structure
    At first I wanted to create a database per user. But this is not scalable. Also an user is an member of a cooperation. I also need to generate reports per cooperation/user.
    So now I was thinking to create a database per cooperation. But now the problem is, when a user login, I need to know wich database to connect to lookup the user data.
    Now I want to use 1 database and each document is an user and holds al data (buildings/logs).

Has anybody got some other suggestions/resources on this approach?

Maybe these tutorials can help:

thnx! couple of them I already knew, but I will still look in to :slight_smile: