简体   繁体   English

在 firestore 子集合上添加实时监听器

[英]Adding realtime listeners on firestore subcollections

Is it possible to have realtime listener on a subcollection in firestore?是否可以在 firestore 的子集合上进行实时监听? I have a subcollection called meetings and when I add a new document the listener is not triggered.我有一个名为会议的子集合,当我添加新文档时,不会触发侦听器。 Below is a sample of my code.下面是我的代码示例。 any idea on what should I do?关于我该怎么做的任何想法? I know I can use top level collection for meetings but in my case I want things to be subcollections way in some parts.我知道我可以将顶级集合用于会议,但在我的情况下,我希望某些部分以子集合的方式出现。

export const getMeetings = (projectId) => {
  const meetingsCollection = firestore.collection('projects-meetings')
  return (dispatch) => {
    meetingsCollection.doc(projectId).collection('meetings').onSnapshot((querySnapShot) => {
      const array = [];
      querySnapShot.forEach(doc => {
        const meeting = { ...doc.data() }
        array.push(meeting)
      })
      dispatch({ type: meetingsActions.GET_MEETINGS_SUCCESS, payload: array });
    }, (err => {
      dispatch({ type: meetingsActions.GET_MEETINGS_ERROR }, err);
    })
    );
  }
};

So figured it out.所以想通了。 The problem was with using Redux-Persist.问题在于使用 Redux-Persist。 I don't know why but it was not fetching data when things were changing in firestore.我不知道为什么,但是当 firestore 发生变化时它没有获取数据。 when I disabled redux persist it worked fine.当我禁用 redux 坚持它工作正常。 But I really want to use redux-persist and I don't know if it is necessary with Firebase local persistence enabled.但是我真的很想使用 redux-persist 并且我不知道是否有必要启用 Firebase 本地持久性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM