How do I make sure to insert the same date when executing batch operations in firebase?

Viewed 31

I have to perform batch query in firebase. This query touches two different collections and inserts date value in each of them. I use firebase.firestore.FieldValue.serverTimestamp(). Part of my query:

async function batchQuery() {
    const batch = db.batch();

    const firstCollectionRef = db
      .collection("firstCollection")
      .doc(id);
    batch.set(firstCollectionRef, {
      someData: data,
      date: firebase.firestore.FieldValue.serverTimestamp(),
    });

    
    const secondCollectionRef = db.collection("secondCollection").doc(id);
    batch.set(
      secondCollectionRef,
      {
        someData: data,
        date: firebase.firestore.FieldValue.serverTimestamp(),
      },
      { merge: true }
    );

    await batch.commit();
  }

How do I make sure that date field in both collections has the same value?

0 Answers
Related