我希望能够将数据保存在Couchbase Lite应用程序中的已删除记录中。根据{{3}},我应该能够使用此代码保存deleted_at
属性以及所有当前属性(稍微针对Swift语法的新时代进行了修改):
do {
try document.update { (newRev) -> Bool in
newRev.isDeletion = true
newRev["deleted_at"] = currentTimeStamp
print("Document deleted at: \(document["deleted_at"])")
// prints "Document deleted at: nil"
print("Revision deleted at: \(newRev["deleted_at"])")
// prints "Revision deleted at: Optional(2016-03-14)"
return true
}
} catch let error as NSError {
self.handleError(error)
}
但是,如果我稍后尝试访问这些属性,则它们不存在:
print("Deleted: \(document.isDeleted)")
// prints "Deleted: Optional(true)"
print("Deleted at: \(document["deleted_at"])")
// prints "Deleted at: nil"
我非常确定这应该打印与deleted_at
属性相关联的时间戳。
我认为也许couchbase不允许从已删除的记录中访问数据,但恢复记录也不允许访问:
do {
try document.update { (newRev) -> Bool in
newRev.isDeletion = false
print("Document deleted at: \(document["deleted_at"])")
// prints "Document deleted at: nil"
print("Revision deleted at: \(newRev["deleted_at"])")
// prints "Revision deleted at: nil"
return true
}
} catch let error as NSError {
self.handleError(error)
}
print("Deleted: \(document.isDeleted)")
// prints "Deleted: Optional(false)"
print("Deleted at: \(document["deleted_at"])")
// prints "Deleted at: nil"
我能做些什么来让它发挥作用吗?
答案 0 :(得分:1)
CBLDocument通常不会加载已删除的修订版。大多数情况下,如果文档被删除,开发人员认为它已经消失,那么CBLDocument.currentRevision
将返回nil而不是返回"墓碑"修订。这会影响属性访问者,调用currentRevision
。
如果您想要获取逻辑删除修订版,因为您在其中存储了数据,您可以使用其他访问者,例如getLeafRevisions
或getRevisionHistory
。
(仅供参考,我写了这段代码,所以这可能是权威的答案:)