javascript - 离线查询上的 React-native-firebase 服务器时间戳
问题描述
我正在尝试使用服务器时间戳字段上的 where 条件进行查询,工作完美,但是当它脱机时,快照不会触发,直到它再次联机。当我删除 where 条件时工作正常。
是否可以使用此服务器时间戳字段脱机工作?还是我做错了什么?
这是我的查询:
firestore()
.collectionGroup(collectionNames.MESSAGES)
.where('chatId', 'in', chatIds)
.where('updatedAt', '>', lastMessageDate)
.onSnapshot({ includeMetadataChanges: true }, onMessage, onError)
这是我的对象:
create({ chatId, type, text, url, user }) {
const { id, email, name, avatarUrl } = user
this.chatId = chatId
this.type = type
this.text = text
this.url = url
this.ownerId = id
this.ownerEmail = email
this.ownerName = name
this.ownerAvatarUrl = avatarUrl
this.updatedAt = firestore.FieldValue.serverTimestamp()
return this.toJSON()
}
解决方案
firestore.FieldValue.serverTimestamp()
已评估服务器端,因此您将无法离线使用它。这是一篇好文章https://medium.com/firebase-developers/the-secrets-of-firestore-fieldvalue-servertimestamp-revealed-29dd7a38a82b
推荐阅读
- vba - 使用 Option Explicit 的 MS Access VBA 给出“变量未定义”错误,但适用于不同的数据库
- machine-learning - Google 机器学习速成课程 MNIST 示例训练在本地 PC 上出现分歧
- javascript - 创建一个猜谜游戏,计算机猜测用户输入的数字
- jsonschema - 如何使用基于布尔值的 Jsonschema Draft 7 if-then-else?
- c# - Windows 的 .NET CLR 与 Linux 或 Mac OS 的不同吗?
- node.js - 有人可以建议一个单行正则表达式来解析带有 - 或 / 分隔符的字母数字和可选数字 id 吗?
- javascript - 向数组中的每个元素添加一个随机数
- python - pytest 使用 Makefile 和 make 命令
- java - 使用“类”作为数据类型是什么意思?
- java - Android Studio 错误 - 缺少类文件