在搜索了一些引用之后。当在数据类中添加字段值时,就足以在firestore文档中创建一个timeStamp了。但在我的情况下,我也是这样做的
资料类别
import com.google.firebase.firestore.ServerTimestamp
import java.sql.Date
data class Banner(
var banner_id:String? = null,
var banner_title:String? = null,
var banner_offer:String? = null,
var banner_image:String? = null,
var banner_priority:String? = null,
var banner_tags:List<String>? = null,
var banner_product_tags:List<String>? = null,
@ServerTimestamp
var banner_timeStamp: Date? = null
)
文档本身未写入或上传到firestore数据库的集合中,也未显示任何错误或异常。删除@ServerTimeStamp字段时,文档以应有的方式上传
实施
override suspend fun addBannersToFirestore(banner: Banner): AddBannerResponse {
return try {
Log.i(TAG,"Banner Upload Started")
val bannerId = bannerRef.document().id
val bannerData = Banner(
banner_id = bannerId,
banner_title = banner.banner_title,
banner_offer = banner.banner_offer,
banner_image = banner.banner_image,
banner_priority = banner.banner_priority,
banner_tags = banner.banner_tags,
banner_product_tags = banner.banner_product_tags
)
bannerRef.document(bannerId).set(bannerData).await()
Success(true)
} catch (e: Exception) {
Failure(e)
}
}
谁能帮我找出错误谢谢
1条答案
按热度按时间yzxexxkh1#
代码中的问题在于使用了不正确的导入:
右边一个是:
更改导入后,将正确添加文档。