Elo*_*ati 3 javascript node.js google-cloud-firestore
我正在使用google的firestore,我希望获得整个系列的实时更新.
我在文档中看到了这一点:https: //cloud.google.com/nodejs/docs/reference/firestore/0.11.x/CollectionReference#onSnapshot
但据我所知,我必须得到一份文件或查询一系列文件.
我怎样才能听取整个系列的变化?
如果您回顾收集文档中的Listen to multiple documents,只需省略where过滤器即可获得整个集合.
第一行看起来像这样: var query = db.collection("cities");
根据我目前的经验,.onSnapshot无需查询 ( .where) 可以帮助您收听整个合集。例如
db.collection('cities')..onSnapshot(function(querySnapshot) {
var cities = [];
querySnapshot.forEach(function(doc) {
cities.push(doc.data().name);
});
console.log("Current cities in CA: ", cities.join(", "));
});
Run Code Online (Sandbox Code Playgroud)
来源:https : //firebase.google.com/docs/firestore/query-data/listen
你也可以在那里阅读更多。
| 归档时间: |
|
| 查看次数: |
4488 次 |
| 最近记录: |