Problems with Sync Gateway

Hi all,

I have several problems about the sync gateway,

(1). I have an existing server with Postgre SQL database, basically I have more than hundreds of user account details (apart from other data) stored in the database (username and password etc). Now I want to migrate to CouchBase server and Sync Gateway (because I have a Android mobile app to replicate data), keeping my existing server as it is. So that means I need to create or transfer those users to Sync Gateway. How do I re-create or transfer user details to SGW? Surely I cannot use “CURL” command because I do not know passwords of each user (since they are encrypted).

Say, if I was able to complete Q1, then,

(2). Is there a way to be ensured about the consistency of data (user account details) between my existing Posgre SQL database and new Sync Gateway database (CouchBase server) ? Which means, if a new user registered to my existing server, new user account details will be stored in the Postgre SQL database, those details should be immediately replicated back to SGW, that is; the user should be created in the SGW also. Is there a way to do that? using Admin REST API or whatever?

(3). In the Sync function, I can route data using channels by assigning different documents to channels based on their “type” property. To that I need to have several if-else-if-else blocks. Say if there are a large number of “document types” . So I need to have a very long and lengthy sync function. This sounds too complicated to me. Is there any way to make this simple, how to manage large number of document types? What if I want to create new document types at run time in both client and server applications? how these new types are handled in sync function?

Anyone please answer me?

Thanks
-Isuru

For #1 and #2, you might want to consider custom authentication using your existing server:
http://developer.couchbase.com/mobile/develop/guides/sync-gateway/administering-sync-gateway/authenticating-users/index.html#custom--indirect--authentication

For #3 - if you need custom processing logic for each document type, I don’t think you can get away from an if/else condition to trigger that code. If you’re simply doing channeling based on a type property, though, you could just use the type name as the channel name - something like channel(doc.type). Channels don’t require explicit creation - they are created when a document is channeled to it - so there’s no issue adding new channels dynamically. You can review http://developer.couchbase.com/mobile/develop/guides/sync-gateway/channels/developing/index.html for some additional background on that topic.

Thanks adam,

But even for Custom Authentication, user accounts has to be created in the sync gateway beforehand, no?

The custom authentication flow has a step to create users via the admin API as needed. These users are created with a random secure password, which doesn’t need to be used (or known) during subsequent session creation.

Yeah. now I get it. that is the answer for my question. Again thank you for fast responding.:slight_smile: