这有效:
db.collection('users').doc('id').get()
.then((docSnapshot) => {
if (docSnapshot.exists) {
db.collection('users').doc('id')
.onSnapshot((doc) => {
// do stuff with the data
});
}
});
Run Code Online (Sandbox Code Playgroud)
......但似乎很冗长.我试过doc.exists,但那没用.我只想在订阅文档上的实时更新之前检查文档是否存在.那个初始的get似乎是对db的一个腰部调用.
有没有更好的办法?
firebase google-cloud-datastore angularfire2 angular google-cloud-firestore