I can do an atomic/multi-location update in Swift using NSNull()
to delete multiple refs. How can I do the same thing in Kotlin using a null type?
let followersRef = "followers/\(otherUserId)/\(currentUserId)"
let followingRef = "following/\(currentUserId)/\(otherUserId)"
let someOtherRef = "someNode/\(currentUserId)"
var multiLocationDict = [String: Any]()
multiLocationDict.updateValue(NSNull(), forKey: followersRef) // <- NSNull() value that deletes this entire ref
multiLocationDict.updateValue(NSNull(), forKey: followingRef) // <-NSNull() value that deletes this entire ref
multiLocationDict.updateValue(1, forKey: someOtherRef) // <- Actual Value that updates or creates another ref
let rootRef = Database().database().reference()
rootRef.updateChildValues(multiLocationDict, withCompletionBlock: { (error, ref) in
// ...
})
Just for a little more clarity in Swift the dictionaries can accept NSNull(). So this works in Swift to delete a ref/path using NSNull(). See an example here
let pathToDelete = "/someRef/\(uid)/someValue"
var dict = [String:Any]()
dict.updateValue(NSNull(), forKey: pathToDelete)
firebaseRootRef.updateChildValues(dict)
But this doesn't work in Kotlin
val pathToDelete = "/someRef/$uid/someValue"
var map = mutableMapOf<String, Any>()
map[pathToDelete] = null
firebaseRootRef.updateChildren(map)