You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* eslint-disable max-len */import*asadminfrom"firebase-admin";import*asfunctionsfrom"firebase-functions/v1";admin.initializeApp();constdb=admin.firestore(functions.config().firebase);constlogCollection="logs";exportconstupdateLogs=functions.pubsub.schedule("every 24 hours",).onRun(async()=>{try{consttotalCollections=awaitdb.listCollections();console.log(`Checking for expired logs in ${totalCollections.length} collections...`);constlogsCollection=db.collection("logs");constlogsSnapshot=awaitlogsCollection.get();console.log(`Checking for expired logs... in ${logCollection} against ${logsSnapshot.size} documents`);if(logsSnapshot.empty){console.log("Not found in logs collection....");return;// Return nothing instead of null}constcurrentDate=newDate();constbatch=db.batch();logsSnapshot.forEach((doc)=>{constlogData=doc.data();constexpiryDateString=logData.expiryDate;// Ensure expiryDate is correctly parsedconstexpiryDate=expiryDateString ? newDate(expiryDateString) : null;// Convert both dates to UTC to ensure correct comparisonconstisExpired=expiryDate ? expiryDate.getTime()<=currentDate.getTime() : false;console.log(`Doc ID: ${doc.id}, Expiry Date: ${expiryDate}, Current Date: ${currentDate}, Is Expired: ${isExpired}`);batch.update(doc.ref,{ isExpired });});awaitbatch.commit();console.log("Expiry check and update completed.");return;}catch(error){console.error("Error checking expiry:",error);}});
V2
/* eslint-disable max-len */import*asadminfrom"firebase-admin";import*asfunctionsfrom"firebase-functions";admin.initializeApp();constdb=admin.firestore(functions.config().firebase);constlogCollection="logs";exportconstupdateLogs=functions.scheduler.onSchedule({schedule: "0 0 * * *",// Runs at midnight UTC every daytimeZone: "Etc/UTC",retryCount: 3,memory: "256MiB",// Optional: Customize memory allocationtimeoutSeconds: 60,// Optional: Set timeout for the function},async(event)=>{try{constlogsCollection=db.collection("logs");constlogsSnapshot=awaitlogsCollection.get();console.log(`Checking for expired logs... in ${logCollection} against ${logsSnapshot.size} documents`);if(logsSnapshot.empty){console.log("Not found in logs collection....");return;// Return nothing instead of null}constcurrentDate=newDate();constbatch=db.batch();logsSnapshot.forEach((doc)=>{constlogData=doc.data();constexpiryDateString=logData.expiryDate;// Ensure expiryDate is correctly parsedconstexpiryDate=expiryDateString ? newDate(expiryDateString) : null;// Convert both dates to UTC to ensure correct comparisonconstisExpired=expiryDate ? expiryDate.getTime()<=currentDate.getTime() : false;console.log(`Doc ID: ${doc.id}, Expiry Date: ${expiryDate}, Current Date: ${currentDate}, Is Expired: ${isExpired}`);batch.update(doc.ref,{ isExpired });});awaitbatch.commit();console.log("Expiry check and update completed.");return;}catch(error){console.error("Error checking expiry:",error);}});
[REQUIRED] Expected behavior
Documents can be fetched from cloud functions without any additional authentication
[REQUIRED] Actual behavior
No collections/documents found
Were you able to successfully deploy your functions?
I tried using v2 and v1 both but with no success to retrieve the firestore documents in cloud functions
Related issues
[REQUIRED] Version info
node:
firebase-functions:
firebase-tools:
firebase-admin:
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
V1
V2
[REQUIRED] Expected behavior
Documents can be fetched from cloud functions without any additional authentication
[REQUIRED] Actual behavior
No collections/documents found
Were you able to successfully deploy your functions?
You can find the complete source code here https://github.com/maheshj01/pastelog/tree/main/functions
The text was updated successfully, but these errors were encountered: