I’m trying to setup replication between few devices and Сouchbase server.
What I’ve done:
Deployed Couchbase server with the only one bucket on local device, installed Couchbase gateway and configured it with the only one user:
“users”: {
“user”: {“password”: “password”, “admin_channels”: ["*"]},
}
Then I created small ios app with the only table view controller. Setup replication objects (pull and push) and liveQuery for listening updates in my local db. Add some data loading and deletion logic. That’s all, I don’t use any other features.
Now, I’m try to test my app in 2 devices: iPhone and iPhone simulator. I do some action to load data to database on my iPhone, for example it adds 10 documents - there is no reaction on iPhone simulator. OK, then I go to Sync Gateway web interface and refresh the page with documents - here they are - 10 documents. Now I go to iPhone Simulator and trying to do the same action - add 10 documents. No reaction on iPhone, but there already 20 document on Sync GateWay page.
Why does it work so? iPhone and simulator app using the same account for authentication. It looks like sync gateway knows something about my devices and does not sharing data between them.
PS. if I drop user authorizing from my code and from Sync Gateway config using default settings:
“GUEST”: {“disabled”: false, “admin_channels”: ["*"] } .
it will work fine!
You will have to provide your user account access to the channel to which the document was added .
As an exercise, add the following lines to your SG config file
This configures a user with credentials “user1” with password “pass” and gives it access to all channels. So if you login with this user account in your iOS app, you should see the user be able to see the documents added to the default channel.
Please review the section on user authorization in this guide , specifically on access .
As a second exercise, configure this in your Sync Gateway config file "users":{ "user1": {"password": "password"}, }
Then in your sync function you can route document to a specific channel and provide user access to it. /* Routing */ // Add doc to the user's channel. channel("channel." + username); access(username,"channel." + username);
Conclusion:
Here’s still some kind of magic when I use special channel “*” - data become isolated by different devices if I has been authorised as same user. Everything goes right if I use special channel “!” or create custom channels.
OK. Thats the public channel so all users have automatic access to it.
Can you reconfirm - Did you try the “second exercise” in my previous response and did that work? (i.e. specifying a channel and giving users access to specific channels) ?
The channel " * " is the all docs channel . If you specify no sync function or custom channels, all docs go into this channel if none specified. But user must be given explicit access to “*” channel.
So can you try this =
Specify “admin_channels”: [“*”] in config file (or use the access method to give access) and
Use empty sync function. (Do not channel document into doc.channels )
function(doc){
if (doc.personId){
channel(doc.personId)
}
}
This is exactly such case when I have a problem with insulation between devices.
OK, I’ll try. Making all channels public is useless in most cases. I need multitenancy behavior and now I know how to achieve this. I’ve create this topic because I’ve met undocumented behaviour. Thank you so much.
" [quote=“ma.kazakov, post:7, topic:13459”]
I need multitenancy behavior and now I know how to achieve this
[/quote]
Thats good! Looks like you have what you need with custom channels .
Yes, the behavior you are observing with the all-docs
" channel is indeed weird. That’s why I wanted to your help to narrow down the issue. Would be great if you can try with an empty sync function and with “admin_channels” to include “*” to see if that made a difference. thanks