I have this data class in Kotlin:
data class Product(
var id: String? = null,
var name: String? = null,
@ServerTimestamp
var createdAt: Date? = null
): Serializable
And this Firestore database:
Root
\
carts <- collection
\
cartId <- document
\
products: [productObj, productObj, productObj]
And I'm trying to add another Product
object to the list. I'm using this line:
cartsRef.document(cartId).update("products", FieldValue.arrayUnion(product)).addOnCompleteListener {}
And I get the following error:
java.lang.IllegalArgumentException: Invalid data. FieldValue.serverTimestamp() can only be used with set() and update()
Why do I get this error since I am using update()
function?