'Firestore emulator inserts twice into collection
I am running functions and firestore emulator. In my index.ts file I call an local function to insert data into firestore to trigger Firestore function event (for testing purposes). For some reason when Firestore Event Function is uncommented it insert data twice into the firestore emulator and if its commented out it only inserts once. Expected behavior is obviously not to insert twice into collection.
// index.ts
// For some reason this function causes insert of 2 records into newOrders collection
export const processNewOrders = functions.firestore.document("newOrders/{orderId}").onCreate(async (snap, context) => {
console.info("New order created");
});
// index.ts
// To trigger Firestore event function
async function generateMockData() {
console.log("Running in emulator");
db.collection("newOrders").add(newOrderMock);
}
generateMockData();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
