有没有办法在 Firebase 中执行原子删除?
docs说
You can also delete by specifying nil as the value for another write operation such as setValue or updateChildValues...Simultaneous updates made this way are atomic: either all updates succeed or all updates fail.
但我无法让它工作。我下面的代码返回错误
Cannot store object of type _SwiftValue at . Can only store objects of type NSNumber, NSString, NSDictionary, and NSArray
我在这里遗漏了什么或者文档有误吗?
var topNodeRef = FIRDatabase.database().reference()
var childUpdates: [String:Any?] = [:]
childUpdates.updateValue(nil, forKey: "/owner")
childUpdates.updateValue(nil, forKey: "/pet")
topNodeRef.updateChildValues(childUpdates)
最佳答案
如果其他人遇到同样的问题,我设法通过使用 NSNull()
而不是 nil
var topNodeRef = FIRDatabase.database().reference()
var childUpdates: [String:Any] = [:]
childUpdates["/owner"] = NSNull()
childUpdates["/pet"] = NSNull()
topNodeRef.updateChildValues(childUpdates)
关于ios - firebase - 在多个位置原子删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40132001/