Skip to content

Commit 40b8cb9

Browse files
authored
Show empty snapshot detection (#24)
2 parents fbe0999 + 3eab552 commit 40b8cb9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

firestore/main/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ function getMultiple(db) {
560560
var citiesRef = db.collection('cities');
561561
var query = citiesRef.where('capital', '==', true).get()
562562
.then(snapshot => {
563+
if (snapshot.empty) {
564+
console.log('No matching documents.');
565+
return;
566+
}
567+
563568
snapshot.forEach(doc => {
564569
console.log(doc.id, '=>', doc.data());
565570
});
@@ -734,7 +739,7 @@ function listenDiffs(db, done) {
734739
// [START listen_diffs]
735740
var observer = db.collection('cities').where('state', '==', 'CA')
736741
.onSnapshot(querySnapshot => {
737-
querySnapshot.docChanges.forEach(change => {
742+
querySnapshot.docChanges().forEach(change => {
738743
if (change.type === 'added') {
739744
console.log('New city: ', change.doc.data());
740745
}

0 commit comments

Comments
 (0)