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. When I remove the where condition works fine.
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:
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. Here is a good article 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.
The timestamp estimation behavior you observe when you specify a SnapshotOptions only works when you have an actual DocumentSnapshot in hand. You can't filter on the estimated value of the timestamp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.