I would like to know the best way to sync my local database with documents in a channel after a user is granted access. Note, the document is not being modified, so there is not change to the document. Here is my setup.
I have two documents
- A userChannel document that contains all the sync gateway channels the user has access to.
- A document that is a part of some channel
A random document is created and synced to all users who currently have access to the channel. Then later, a new user comes along and is granted access to the channel that contains this document via the userChannel document. What I have determined is that simply adding a user to a channel (granting access in the sync gateway) does not replicate all the documents within that channel down to the user. I wish it did.
So now, I would like to sync all the documents within this channel down to the new user that was just granted access to the channel. What is the best way to do this?
I have tried a one shot pull replication of the channel (and doc id) with no success. Here is the code
/******************************************************************************/
func syncDocs(doc_ids: [String])
{
if (myUsername != "" && myPassword != "")
{
for id in doc_ids
{
logger.log(message: "Syncing doc \(id) ", event: .i)
}
let pull = db.createPullReplication(kSyncGatewayUrl)
let authenticator = CBLAuthenticator.basicAuthenticator(withName: myUsername,
password: myPassword)
pull.authenticator = authenticator
// pull.channels = [channel_ids]
pull.documentIDs = doc_ids
pull.start()
}
else
{
logger.log(message: "Tried to sync docs. Username nor password is set", event: .e)
}
}
I have tried setting just the “documentIDs” property, just the “channels” property, and both together. Nothing syncs down to the local database.
Another approach is to use the Rest API and GET the document. But then the document is returned, not synced to the local database. So I would then have to add it to the local database… By using “putProperties”?
Summary: How do I sync/pull all the documents from a channel that a user was just granted access to?
Oh, I almost forgot. To test this, I am purging the random document from my local database. Once the document is purged, I get logger errors in my code saying that the document no longer exist on the local database… which is great and expected. Now, I would like to be able to re-sync all the documents within a channel that I have access to. Which should bring back the document that was purged.
Thank you
Sean