Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
Check an event type of currently affected document in firestore

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:

  1. Creating a new document
    Given there is no document in products collection with a document id xbox
    Then it would create a new one.

  2. 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 ?

Real-life example when listening to Firestore

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() ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The set() just returns Promise<void> so you cannot check if document is new or existing document was updated using that. You'll have to check for document's existence before using set().

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!