-
Notifications
You must be signed in to change notification settings - Fork 986
Closed
Description
Operating System
Mac OS Sonoma
Browser Version
Chrome/124.0.6367.158
Firebase SDK Version
Admin Node.js 12.1.0
Firebase SDK Product:
Firestore
Describe your project's tooling
Node js app to build a bar chart using some d3.js.
Describe the problem
I am trying to dynamically update a d3.js barchart based on a Firestore database using the onSnapshot function in my node.js app. The connection seems to be working in general, as the app does correctly pull the data and render the chart the first time it is opened, but it does not update as expected when I delete/change/add data to Firestore database in the browser.
Steps and code to reproduce issue
Get route from index.js file
app.get('/', (req, res) => {
const unsubscribe = db.collection('dishes').onSnapshot(snapshot => {
const documents = [];
snapshot.forEach(doc => {
documents.push(doc.data());
});
const documentsJSON = JSON.stringify(documents);
res.render('barchart', { documentsJSON }); // Pass data to the template
}, err => {console.log("error!");
});
// detach listener
req.on('close', () => {
unsubscribe();
});
});
Data is then processed using code in render_code.js, which is embedded in the handlebars as follows:
<script type="text/javascript" src = '/render_code.js' data-documents='{{{documentsJSON}}}'>
</script>