繁体   English   中英

离线查询上的 React-native-firebase 服务器时间戳

[英]React-native-firebase server timestamp on offline queries

我正在尝试使用服务器时间戳字段上的 where 条件进行查询,工作完美,但是当它脱机时,快照不会触发,直到它再次联机。 当我删除 where 条件时工作正常。

是否可以使用此服务器时间戳字段脱机工作? 还是我做错了什么?

这是我的查询:

firestore()
  .collectionGroup(collectionNames.MESSAGES)
  .where('chatId', 'in', chatIds)
  .where('updatedAt', '>', lastMessageDate)
  .onSnapshot({ includeMetadataChanges: true }, onMessage, onError)

这是我的 object:

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

由于服务器时间戳是在服务器上评估的,因此在文档最终同步之前它们没有实际值。 这意味着您将无法使用该字段进行过滤 - 在服务器上发生写入之前,该值实际上是 null。

您在指定SnapshotOptions时观察到的时间戳估计行为仅在您手头有实际 DocumentSnapshot 时才有效。 您无法过滤时间戳的估计值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM