*grml* - still no luck using those API's. And I truly running out of ideas
:(
Do you have any idea what's going wrong here?
The sad news are, the deletion of the remote documents doesn't seem to have
any effect at all :(
I've got the following databaseRestoreBackup func:
func databaseRestoreBackup(database: CBLDatabase, from date: NSDate,
withManager databaseManager: CBLManager) throws -> CBLDatabase?{
...
//delete the old database
try databaseDelete(database, withManager: databaseManager)
//Unzip backup to the manager directory
SSZipArchive.unzipFileAtPath(sourcePath, toDestination:
databaseManager.directory)
//create new revisions of the restored documents
let database = try databaseManager.databaseNamed(database.name)
let enumerator = try database.createAllDocumentsQuery().run()
for i in 0..<enumerator.count{
if let doc = enumerator.rowAtIndex(i).document {
try doc.newRevision().save()
}
}
//purge all remote documents
try PersistenceManager.sharedInstance().purgeRemoteDocuments(channel:
Identity.sharedInstance().tenant, completion: { (result: AnyObject?) ->
Void in
do{
try self.databaseStartReplication(database, completion: { (notification) ->
Void in
PersistenceManager.sharedInstance().databaseSetup(database, withManager:
databaseManager)
})
} catch let error as NSError{
NSLog(error.localizedDescription)
}
})
...
}
Which calls the following purgeRemoteDocuments func (Is there a better way
reading only the docs of the given channel?):
func purgeRemoteDocuments(channel channel: String, completion:
CompletionHandler? = nil) throws{
guard let serverURL = self.replicationConfig["url"] as? NSURL,
let serverDatabase = self.replicationConfig["database"] as? String,
let serverUsername = self.replicationConfig["username"] as? String,
let serverPassword = self.replicationConfig["password"] as? String
else { throw PersistenceManagerError.ConfigInvalid }
Alamofire.request(.GET,
serverURL
.URLByAppendingPathComponent(serverDatabase)
.URLByAppendingPathComponent("_all_docs"),
parameters:[ "channels":"true" ])
.authenticate(user: serverUsername, password: serverPassword)
.responseJSON { response in switch response.result {
case .Success(let data):
let json = JSON(data)
if let documents = json["rows"].array{
for document in documents{
if let channels = document["value"]["channels"].arrayObject as? [String]{
if channels.indexOf(channel) != nil{
if let docID = document["id"].string{
Alamofire.request(.DELETE,
serverURL
.URLByAppendingPathComponent(serverDatabase)
.URLByAppendingPathComponent(docID))
.authenticate(user: serverUsername, password: serverPassword)
.responseJSON { response in switch response.result {
case .Success(_):
NSLog("Deleted remote document with id '\(docID)'")
case .Failure(let error):
NSLog(error.localizedDescription)
}
}
}
}
}
}
}
if let handler = completion{
handler(result: data)
}
case .Failure(let error):
NSLog(error.localizedDescription)
if let handler = completion{
handler(result: error)
}
}
}
}
Am Sonntag, 22. November 2015 20:41:04 UTC+1 schrieb
[email protected]:
>
> Ok; I think I got it.
>
> It seems I'm able to read all documents using this:
>
> http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/database/get-all-docs/index.html
>
> And afterwards deleting every single document using the following request
> for each one:
>
> http://developer.couchbase.com/documentation/mobile/1.1.0/develop/references/sync-gateway/rest-api/document/delete---db---doc-/index.html
>
> Am Sonntag, 22. November 2015 20:35:01 UTC+1 schrieb
> [email protected]:
>>
>> Hi Jens
>>
>> Thank you very much for pointing me into the right direction. I'd like
>> the "delete-all-documents-of-given-channel-from-server" approach.
>> Unfortunately I can't figure out how I'd exactly do this.
>>
>> I've found the Delete design documents
>> <http://docs.couchbase.com/admin/admin/REST/rest-ddocs-delete.html> API
>> description, but can't see how I'd pass the channel id as argument?
>>
>> Hoping you can give me a brief hint.
>> Thank you very much!!
>>
>>
>> Am Sonntag, 22. November 2015 19:49:44 UTC+1 schrieb Jens Alfke:
>>>
>>>
>>> On Nov 22, 2015, at 2:31 AM, Brendan Duddridge <[email protected]>
>>> wrote:
>>>
>>> Well that definitely complicates things. Perhaps another way to reset
>>> back to a previous state would be to purge all the documents on the server
>>> for a specific channel?
>>>
>>>
>>> Yeah, I’d recommend that too, although it does cause everything to get
>>> uploaded back to the server, which can take a while.
>>>
>>> (But there’s the problem that for some reason SG hasn’t implemented the
>>> _purge call. It’s pretty easy to do a purge using CB Server APIs though:
>>> just delete the docs.)
>>>
>>> —Jens
>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/270c05ae-3e77-4671-951d-39dc33597939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.