The documentation says:
You can listen to a document with the onSnapshot() method. An initial call using the callback you provide creates a document s
After reading the first and second solution, I have made a solution that seems to work.
First you initialize a variable to true and inside the onSnapshot() method you check if this variable is true, if it is, you change it to false, and on else you write your retrieving data algorithm. Something like this:
var initState = true;
let observer = records.onSnapshot(docSnapshot => {
console.log(`Received doc snapshot`);
if (initState) {
initState = false;
} else {
if (!docSnapshot.docChanges().empty) {
docSnapshot.docChanges().forEach(function (change) {
//Write here wahtever you want
});
}
}
}, err => {
console.log(`Encountered error: ${err}`);
});