I followed the tutorial here on how to batch write items to Firestore. However, this does not seem to work as I get a type error
Argument of type 'CollectionReference<DocumentData>' is not assignable to parameter of type 'DocumentReference<DocumentData>'.
Types of property 'type' are incompatible.
Type '"collection"' is not assignable to type '"document"'
const batchLog = async (
data: LogData[] & CommonLogData[],
sessionId: string | null,
) => {
if (!sessionId) {
console.error('attempting to log item without a session id', data);
}
// Get a new write batch
const batch = writeBatch(db);
// for each data, set the batch
data.forEach(datum => {
const docRef = collection(
db,
rootCollection,
sessionId || 'error',
datum.collection_name,
);
batch.set(docRef, doc);
});
await batch.commit();
};
Quite simply, I want to be able to run an addDoc but have it batched. It seems as if this only works for the documents but not collections. I am very new to this, so any help would be appreciated. Currently, I believe this code fails silently (I don't see my data in the firestore update)