【发布时间】:2018-04-03 11:14:15
【问题描述】:
这行得通:
db.collection('users').doc('id').get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
db.collection('users').doc('id')
.onSnapshot((doc) => {
// do stuff with the data
});
}
});
...但它似乎很冗长。我试过doc.exists,但没用。我只想检查文档是否存在,然后再订阅它的实时更新。最初的 get 似乎是对 db 的浪费调用。
有没有更好的办法?
【问题讨论】:
-
您是要完成插入/更新还是?
-
现在是
db.collection('users').doc('id').ref.get()
标签: javascript google-cloud-firestore