0

First of all I know NOSQL systems do not have JOIN. But I know there is a way for getting a datas with another table values.

About my app: This app is basic social network app. People can share photos. These posts saving firebase database 'realtime database' not cloud firestore than it has a timeline page. this page shows shared posts. I need to show posts with publisher information.

Users login with firebase authentication and I have users table called kullanici like this. kullanici table

I have Posts table like this. posts table

I need to delete displayName in Posts table than get isim in kullanici table.

my needed data is: Post with kullanici->{posts.{postid}.userid}->isim.

my working code is below:

return (dispatch) => {
    firebase.database().ref(`/posts`).endAt("tarih").limitToLast(2)
      .on('value', snapshot => {
        dispatch({type: STUDENT_LIST_DATA_SUCCESS, payload: snapshot.val()});
      });
  };

my returned data is below:

Object {
  "-L9tnfvm6jQiKLc378c6": Object {
    "aciklama": "",
    "baslik": "Ensar mı Ahmet mi",
    "displayName": "HasanRiza",
    "image": "https://hasan-riza-uzuner.s3.amazonaws.com/1523535677033.png",
    "like": 244,
    "tarih": 1523535757133,
    "userid": "fD7IfKAhXogFwHtfKYiF7LMtXNp1",
  },
  "-LYHPJgR4sywTzpcxX7A": Object {
    "aciklama": "Ev",
    "baslik": "Nasıl",
    "displayName": "HasanRiza",
    "image": "https://hasan-riza-uzuner.s3.us-east-2.amazonaws.com/1549718296409.png",
    "like": 1,
    "tarih": 1549718342522,
    "userid": "fD7IfKAhXogFwHtfKYiF7LMtXNp1",
  },
}
Hasan Rıza Uzuner
  • 445
  • 1
  • 7
  • 21
  • There are two possible solutions. 1) duplicate the data that you need under each post, 2) perform an extra `refToUsersNode.child(theUserToLoad).once('value'` for each user. – Frank van Puffelen Feb 24 '19 at 04:52
  • can you give an example for both of them ? – Hasan Rıza Uzuner Feb 24 '19 at 07:38
  • See https://firebase.googleblog.com/2013/10/queries-part-1-common-sql-queries.html, https://stackoverflow.com/questions/47868991/join-two-nodes-in-firebase – Frank van Puffelen Feb 24 '19 at 14:55
  • [https://stackoverflow.com/questions/54774443/how-can-i-join-data-with-react-native-and-a-many-to-many-firebase-firestore-coll](https://stackoverflow.com/questions/54774443/how-can-i-join-data-with-react-native-and-a-many-to-many-firebase-firestore-coll) That link help to you! – Tolga EGE Jun 22 '20 at 19:38

1 Answers1

-1
var promises = [];
group_ids.forEach(function (group_id) {
    promises.push(firebase.firestore().collection('Group').doc(group_id).get())
});
Promise.all(promises).then(function(docs) {
    docs.forEach((groupDoc) => {
        group.name = groupDoc._data['name'];
        group.city = groupDoc._data['city'];
        group.state = groupDoc._data['state'];
        groups.push(group);
    });
    console.log(groups);
});
Tolga EGE
  • 11
  • 1
  • Please add some context to your answer and explain how it solves the question asked. – Leo Jun 22 '20 at 20:16