I need to fetch sub-set of documents in Firestore collection modified after some moment. I tried going theses ways:
It seems that native filtering can work only with some real fields in stored document - i.e. nevertheless Firestore API internally has DocumentSnapshot.getUpdateTime() I cannot use this information in my query.
I tried adding my _lastModifiedAt 'service field' via server-side firestore cloud function, but ... that updating of
_lastModifiedAt
causes recursive invocation of theonWrite()
function. I.e. is does also not work as needed (recursion finally stops withError: quota exceeded (Function invocations : per 100 seconds)
).
Are there other ideas how to filter collection by 'lastModifiedTime'?
Here is my 'cloud function' for reference
- It would work if I could identify who is modifying the document, i.e. ignore own updates of
_lastModified
field, but I see no way to check for this _lastModifiedBy
is set to null because of current inability of Firestore to provideauth
information (see here)
exports.updateLastModifiedBy = functions.firestore.document('/{collId}/{documentId}').onWrite(event => {
console.log(event.data.data());
var lastModified = {
_lastModifiedBy: null,
_lastModifiedAt: now
}
return event.data.ref.set(lastModified, {merge: true});
});