Use Sync Gateway for independant buckets

So I have 1 type client that needs to sync to a particular bucket. I also have another type of client that needs to sync to another bucket. Is it possible to implement this without having 2 sync gateways?

@Epwna

You can map multiple Sync Gateway DB’s to different buckets e.g. to map two DB’s ‘db1’ and ‘db2’ you could do something like this:

{
	"databases": {
		"db1": {
			"server": "http://localhost:8091",
      		"bucket": "bucket-1",
			"sync": `function(doc){channel(doc.channels);}`,
			"users": {
				"GUEST": {"disabled": false, "admin_channels": ["*"]}
			}
		},
		"db2": {
			"server": "http://localhost:8091",
      		"bucket": "bucket-2",
			"sync": `function(doc){channel(doc.channels);}`,
			"users": {
				"GUEST": {"disabled": false, "admin_channels": ["*"]}
			}
		}
	}
}

Andy

1 Like

So I’d do the same thing even if those 2 buckets were technically on the same database? The name of the database doesn’t really matter in the configuration?

My cluster is called master_east but could my configuration look like this :

{
	"databases": {
		"master_east_analytics": {
			"server": "http://localhost:8091",
      		"bucket": "bucket-1",
			"sync": `function(doc){channel(doc.channels);}`,
			"users": {
				"GUEST": {"disabled": false, "admin_channels": ["*"]}
			}
		},
		master_east_spark": {
			"server": "http://localhost:8091",
      		"bucket": "bucket-2",
			"sync": `function(doc){channel(doc.channels);}`,
			"users": {
				"GUEST": {"disabled": false, "admin_channels": ["*"]}
			}
		}
	}
}

And in code I could do two separate replication calls like:

mDatabase.createPullReplication(“http://0.0.0.0:4984/master_east_analytics/”);
mDatabase.createPullReplication(“http://0.0.0.0:4984/master_east_spark/”);

@Epwna

Yes, that will work.

In your example “server”: “http://localhost:8091” is pointing to a Couchbase Server node in a cluster, even if it’s a cluster of one.

In the Couchbase Server Admin console you would create two buckets, “bucket-1” and “bucket-2”, these are completely isolated from each other, but running across the same cluster of Couchbase Servers.

Andy

1 Like

Excellent. Thank you very much for your help!