var allCities = citiesRef.get() .then(snapshot => { snapshot.forEach(doc => { console.log(doc.id, '=>', doc.data()); }); }) .catch(err => { console.log('Error getting documents', err); }); Firebase 教學 {description: "寄發email給客⼾戶", done: false, key: "EO0nJoDxGvm3PdEtyfFI"} {description: "跑步", done: false, key: "O5p4F7W77LarvQfmlNUD"} EO0nJoDxGvm3PdEtyfFI => O5p4F7W77LarvQfmlNUD => Get all documents in a collection(重複監聽) let Ref = db.collection('messages'); Ref.onSnapshot((snapshot) => { snapshot.docChanges().forEach(change => { if(change.type=='added'){ console.log(change.doc.id, '=>', change.doc.data()); } }); }); Get all documents in a collection+排序 let Ref = db.collection(‘messages’).orderBy(‘timestamp’); Ref.onSnapshot((snapshot) => { snapshot.docChanges().forEach(change => { if(change.type=='added'){ console.log(change.doc.id, ‘=>', change.doc.data()); } }); });