首页 > 解决方案 > 离线查询上的 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()
}

标签: javascriptfirebasereact-nativegoogle-cloud-firestorereact-native-firebase

解决方案


firestore.FieldValue.serverTimestamp()已评估服务器端,因此您将无法离线使用它。这是一篇好文章https://medium.com/firebase-developers/the-secrets-of-firestore-fieldvalue-servertimestamp-revealed-29dd7a38a82b


推荐阅读