【发布时间】:2019-07-31 22:29:07
【问题描述】:
我有这个映射器,它执行以下操作:
override fun map(model: Model) = mapOf<String, Any?>(
...,
KEY_TIMESTAMP to (model.timestamp.takeIf { it > -1 } ?: ServerValue.TIMESTAMP),
...
)
当我需要将更多模型同时发布到不同的位置时,我会使用映射器并将模型转换为 Map<String, Any?>。
所以我有一堆地图,然后合并到一个大的Map<String, Any?> 看起来像这样:
{
"messages/-L_bXQUibioB6OMkl0SE/text": "Android Developer created this conversation",
"messages/-L_bXQUibioB6OMkl0SE/senderName": "system",
"messages/-L_bXQUibioB6OMkl0SE/senderAvatarUrl": null,
"messages/-L_bXQUibioB6OMkl0SE/timestamp/.sv": "timestamp",
"messages/-L_bXQUibioB6OMkl0SE/attachment": null,
"chats/participants/UZ684hcHTnOkaglUX0QwbR9DK442/name": "cool guy",
"chats/participants/UZ684hcHTnOkaglUX0QwbR9DK442/imageUrl": null,
"chats/participants/aqiTRMAUOSdJIuEOvNJpeAb4D0F3/name": "Android Developer",
"chats/participants/aqiTRMAUOSdJIuEOvNJpeAb4D0F3/imageUrl": "https://firebasestorage...",
"chats/lastMessage": "Android Developer created this conversation",
"chats/lastMessageTimestamp/.sv": "timestamp",
"chats/name": null,
"chats/imageUrl": null,
"chats/type": "SINGLE"
}
那么我就这样做了:
ovveride fun updateChildren(data: Map<String, Any?>) = Completable.create { emitter ->
rootRef.updateChildren(data) { databaseError, _ ->
databaseError?.toException()
?.let(emitter::onError)
?: emitter.onComplete()
}
}
当最后一个代码被调用时,我得到了以下异常:
com.google.firebase.database.DatabaseException: Path '/messages/-L_bXQUibioB6OMkl0SE/timestamp/.sv' contains disallowed child name: .sv
at com.google.firebase.database.core.utilities.Validation.parseAndValidateUpdate(com.google.firebase:firebase-database@@16.0.5:140)
at com.google.firebase.database.DatabaseReference.updateChildrenInternal(com.google.firebase:firebase-database@@16.0.5:428)
at com.google.firebase.database.DatabaseReference.updateChildren(com.google.firebase:firebase-database@@16.0.5:418)
如果可能的话,我怎样才能解决这个问题并继续使用 ServerValue.TIMESTAMP?
【问题讨论】:
标签: android firebase firebase-realtime-database timestamp