Why does Firebase trigger multiple events (including old ones) when a new document is added in Firestore?

This topic was automatically generated from Slack. You can find the original thread here.

i am using firebase trigger(new document in firestore) . it should give event for newly added document but it is giving so many events (old ones) to the workflow. why is this happening

I’m sorry to hear that you’re experiencing issues with the Firebase trigger. To better assist you, can you please provide more information about your workflow setup and the specific trigger you’re using? This will help me understand the issue and provide a more accurate solution.

i am using new document in forestore trigger and on recieving event running next steps

I understand that you’re using the “New Document in Firestore” trigger and experiencing issues with receiving multiple events, including old ones. To help you further, can you please provide more details about your workflow, such as: 1. The configuration of your Firestore trigger, including the collection path. 2. Any filters or conditions you’ve set up in the trigger or the workflow. 3. The steps you’re running after the trigger event. This information will help me better understand the issue and provide a more accurate solution.

we are using this configuration in trigger, polling as 5:45 am utc , query is { “select”: { “fields”: [] }, “from”: [ { “collectionId”: “collectionname”, “allDescendants”: “true” } ] }

Thank you for providing the configuration details. It seems like you’re using a custom Firestore query with a scheduled trigger to poll for new documents at 5:45 AM UTC. However, the “New Document in Firestore” trigger you mentioned earlier is a different trigger that listens for real-time updates. To avoid receiving old events, you can try the following: 1. Use the built-in “New Document in Firestore” trigger instead of a custom query with a scheduled trigger. This trigger listens for real-time updates and should only emit events for newly added documents. 2. If you still prefer to use a scheduled trigger with a custom query, you can add a timestamp field to your Firestore documents and update your query to only fetch documents that were created after the last polling time. You’ll need to store the last polling time in a variable and update it after each successful run. Please let me know if you need further assistance or if you have any questions about the suggested solutions.

And post trigger there are 3 steps :
1.calculates start time of workflow
2.get data from newly created document
3.based on few conditions creates new document in another collection

Based on the information you provided, here’s a suggested workflow structure: 1. Use the “New Document in Firestore” trigger. 2. Add a code step to calculate the start time of the workflow. 3. Add a code step to get data from the newly created document. 4. Add a code step to create a new document in another collection based on certain conditions. Here’s a sample code for steps 2-4: ```
// Step 2: Calculate start time of the workflow const startTime = new Date(); // Step 3: Get data from the newly created document const newDocumentData = this.event.data; // Assuming ‘this.event.data’ contains the new document data // Step 4: Create a new document in another collection based on certain conditions if (/** your conditions here /) { const newCollectionRef = / firestore reference to the new collection **/; await newCollectionRef.add(newDocumentData); }

i am using new document in firestore itself

I see that you’re using the “New Document in Firestore” trigger. If you’re still experiencing issues with receiving multiple events, including old ones, you can try the following troubleshooting steps: 1. Double-check your Firestore trigger configuration to ensure it’s set up correctly, and make sure you’re listening to the correct collection. 2. Verify if there are any other processes or workflows that might be causing the old documents to be updated or modified, which could trigger the event. 3. Check if there are any errors or unexpected behavior in your workflow steps that might be causing the issue. If the issue persists, please provide more details about your workflow and any errors or logs you encounter. You can also reach out to Pipedream support at https://pipedream.com/support for further assistance.