这有效:
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,但是没有用。我只想检查该文档是否存在,然后再订阅它的实时更新。最初的获取似乎浪费了对数据库的调用。
有没有更好的办法?