У меня есть такая структура чата:
Теперь я хочу заполнить чаты, чтобы пользователь видел только те чаты, где он является участником чата. Как вы можете видеть, у каждого чата есть узел участников, есть идентификатор пользователя из firebase. Как я могу отфильтровать это в моем запросе? Теперь я получаю чаты так:
constructor(props) {
super(props);
this.state = { chats: [] };
this.getChats = this.getChats.bind(this);
}
componentDidMount() {
var _userId = firebase.auth().currentUser.uid;
this.getChats(_userId);
}
getChats = _userId => {
var readedData = firebase
.database()
.ref('chats')
.orderByKey();
readedData.once('value', snapshot => {
this.setState({ chats: snapshot.val() });
console.log(this.state.chats);
});
};
Спасибо за помощь! Новая структура: