I am currently facing a challenge in retrieving the first 2 documents from a collection in google cloud firestore. My current approach involves using the timestamp of the latest document and then calculating the time range to fetch the desired documents.
let firstStamp: number = [example timestamp in ms]
const query: any = await admin.firestore().collection('collection').where('timestamp', '<', firstStamp);
let documents: any;
query.where('timestamp', '>', firstStamp - 15000);
return query.get().then(result => {
if (result.size === 0) {
log(`No data. If this happens i've done something wrong with my query.`);
return;
};
documents = result.docs;
});
Despite not encountering any error messages or logs, this solution is not yielding the expected results. Can anyone identify what might be going wrong?
If there are alternative methods to achieve this task more effectively, I would greatly appreciate some guidance.