简体   繁体   English

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

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

I'm trying to query with a where condition on a server timestamp field, work's perfectly, but when it's offline the snapshot do not trigger until it's online again.我正在尝试使用服务器时间戳字段上的 where 条件进行查询,工作完美,但是当它脱机时,快照不会触发,直到它再次联机。 When I remove the where condition works fine.当我删除 where 条件时工作正常。

Is it possible to work offline with this server timestamp field?是否可以使用此服务器时间戳字段脱机工作? Or am I doing something wrong?还是我做错了什么?

here's my query:这是我的查询:

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

and here's my object:这是我的 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() is evaluated server side so you will not be able to use it offline. firestore.FieldValue.serverTimestamp()在服务器端进行评估,因此您将无法离线使用它。 Here is a good article https://medium.com/firebase-developers/the-secrets-of-firestore-fieldvalue-servertimestamp-revealed-29dd7a38a82b这是一篇好文章https://medium.com/firebase-developers/the-secrets-of-firestore-fieldvalue-servertimestamp-revealed-29dd7a38a82b

Since server timestamps are evaluated on the server, they don't have an actual value until the document finally gets synchronized.由于服务器时间戳是在服务器上评估的,因此在文档最终同步之前它们没有实际值。 That means you won't be able to filter using that field - the value is effectively null until the write happens on the server.这意味着您将无法使用该字段进行过滤 - 在服务器上发生写入之前,该值实际上是 null。

The timestamp estimation behavior you observe when you specify a SnapshotOptions only works when you have an actual DocumentSnapshot in hand.您在指定SnapshotOptions时观察到的时间戳估计行为仅在您手头有实际 DocumentSnapshot 时才有效。 You can't filter on the estimated value of the timestamp.您无法过滤时间戳的估计值。

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

相关问题 当离线模式处于活动状态时,react-native-firebase 是否安全? - Is react-native-firebase secure when offline mode is active? react-native-firebase重新发送消息代码 - react-native-firebase resend message code react-native-firebase getInitialNotification循环 - react-native-firebase getInitialNotification loop React-Native-Firebase:RTDB 模拟器 - React-Native-Firebase : RTDB Emulator 使用 react-native-firebase 时添加对 Android 通知的回复 - Add replies to Android notifications while using react-native-firebase 二阶通过查询在Firestore中不执行任何操作(react-native-firebase) - Second orderBy query does nothing in Firestore (react-native-firebase) listRef.listAll() 函数未定义(react-native-firebase) - listRef.listAll() function is undefined (react-native-firebase) iOS 无法在 react-native-firebase 中接收通知 - iOS can't receive notifications in react-native-firebase iOS 远程通知不起作用 react-native-firebase [v6] - iOS remote notification not working react-native-firebase [v6] 哪个 Firebase javascript package 应该与 React Native 一起使用? 常规的“Firebase Web SDK”还是“react-native-firebase”? - Which Firebase javascript package should be used with React Native? The regular "Firebase Web SDK " or "react-native-firebase"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM