I have issue with pull. Push works but pull works only after I configure database, so I need to configure database every time I push something. I am building app where I need to push and pull several documents. Can someone help?
Here is my Replication function
func startPushAndPullReplicationForCurrentUser(){
guard let remoteUrl = URL.init(string: remoteSyncUrl) else{
print(UserProfileError.RemoteDatabaseNotReachable)
return
}
guard let user = self.currentUserCredentials?.user, let password = self.currentUserCredentials?.password else{
print(UserProfileError.UserCredentialsNotProvided)
return
}
guard let database = database else {
print(UserProfileError.DatabaseNotInitialized)
return
}
if pushPullReplicator != nil{
return
}
let databaseUrl = remoteUrl.appendingPathComponent(databaseName)
var config = ReplicatorConfiguration.init(database: database, target: URLEndpoint.init(url: databaseUrl))
config.replicatorType = .pushAndPull
config.continuous = true
config.authenticator = BasicAuthenticator(username: user, password: password)
let userChannel = "channel.\(user)"
config.channels = [userChannel]
pushPullReplicator = Replicator.init(config: config)
pushPullReplicatorListener = pushPullReplicator?.addChangeListener({ (change) in
let s = change.status
switch s.activity {
case .busy:
print("Busy transferring data")
case .connecting:
print("Connecting to Sync Gateway")
case .idle:
print("Replicator in Idle state")
case .offline:
print("Replicator in offline state")
case .stopped:
print("Completed syncing documents")
}
if s.progress.completed == s.progress.total {
print("All documents synced")
}
else {
print("Documents \(s.progress.total - s.progress.completed) still pending sync")
}
})
pushPullReplicator?.start()
}
Here is my database config
{
“bucket”: “receipts”,
“num_index_replicas”: 0,
“import_docs”: true,
“name”: “receipts”,
“guest”: {
“disabled”: false
},
“delta_sync”: {
“enabled”:false
},
“enable_shared_bucket_access”: true,
“sync”: function sync(doc, oldDoc){ channel("channel."+doc.email); }
}
When I reconfig database there is new document in database called _sync:local:checkpoint/cp-aKhDXYcvGqbUrVmQkZAFoLWG+XY= and it contains {“time”:1649323584,“local”:1,“remote”:4,"_rev":“0-2”}
What do you mean by “reconfig your database”?
Updating database config with /{db}/_config