我在Kotlin中有以下数据类:
data class Product(
var id: String? = null,
var name: String? = null,
@ServerTimestamp
var createdAt: Date? = null
): Serializable
而这个Firestore数据库:Root
\
carts <- collection
\
cartId <- document
\
products: [productObj, productObj, productObj]
我正在尝试将另一个Product
对象添加到列表中。我正在使用以下行:cartsRef.document(cartId).update("products", FieldValue.arrayUnion(product)).addOnCompleteListener {}
我收到以下错误:java.lang.IllegalArgumentException: Invalid data. FieldValue.serverTimestamp() can only be used with set() and update()
为什么由于使用
update()
函数而出现此错误?
最佳答案
在您的数据类中,您应该尝试将@ServerTimestamp
更改为
@ServerTimestamp private val serverTimestamp:Date
关于android - 由于错误,无法在Firestore中更新阵列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62814364/