[英]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.