Is there a way to set and merge without creating a map for just 1 value

Viewed 105

I'm planning to add just one more value into my user

docRef.document(FirebaseAuth.getInstance().currentUser!!.uid)
    .set("hasShop", SetOptions.merge())

Now, I want to say that this hasShop value should be true, but I dont want to do this

val map = hashMapOf<String,Any>
map["hasShop"] = true
docRef.document(FirebaseAuth.getInstance().currentUser!!.uid)
    .set(map, SetOptions.merge())

Is there a better way to do it like this ?

 docRef.document(FirebaseAuth.getInstance().currentUser!!.uid)
    .set("hasShop" {true} , SetOptions.merge())
1 Answers

You can use update() to set a value on an existing document.

 docRef.document(FirebaseAuth.getInstance().currentUser!!.uid)
    .update("hasShop", true)
Related