Is there a way to check what was happened with currently affected document in Firestore collection?
Was it updated or it has created a new document?
For example to create a new document we can use this:
await db.collection('products').doc('xbox').set({ price: 300 });
I would like to get a feedback event for 2 following scenarios:
Creating a new document
Given there is no document in products collection with a document id xbox
Then it would create a new one.
Updating an existing document
Given there is already an existing document with an id xbox.
Then it should update it.
The question is:
How to get that info if it was created or updated ?
For example when listening to a realtime firestore updates, we can get that info like so:
db.collection('products').onSnapshot(snapshot => {
snapshot.docChanges().forEach(change => {
// Document write mode:
console.log(change.type) // could be: added, modified, removed
})
})
Is there something similiar tp change.type when modifying a document in firestore without actually listening to it but only using .set() ?