From the documentation on firestore batch writes and transactions, what I understand, and please correct me if I am mistaken, that transactions atomic document writes after reads, and so that all read operations have to be made before the writes inside of a transaction.
But my question can the writes be made to the realtime database instead of firestore?
For example taking the snippet inside the documentation, will replacing the firestore update(write) to the city document population counter, with a firebase set(write) to a /populations/counter
work ?
// Initialize document
var cityRef = firestore.collection('cities').doc('SF');
var setCity = cityRef.set({
name: 'San Francisco',
state: 'CA',
country: 'USA',
capital: false,
population: 860000
});
var transaction = firestore.runTransaction(t => {
return t.get(cityRef)
.then(doc => {
// Add one person to the city population
var newPopulation = doc.data().population + 1;
// ***** DOCUMENTATION WRITE OPERATION*****
// t.update(cityRef, {population: newPopulation});
// ***** CODE IN QUESTION *****
realtimeDatabase().ref('/counters/population').set(newPopulation)
});
}).then(result => {
console.log('Transaction success!');
}).catch(err => {
console.log('Transaction failure:', err);
});