0

How can I recursive query key with re-base?

I have the follow structure..

comments/{ROOM_ID}: {
    {COMMENT_ID}: { 
        <COMMENT_DATA> 
        comments: { 
            <OTHERS_REPLIED_COMMENTS> 
        } 
    }
}

enter image description here

And I want to push new replied comment ... I tried:

export async function addReplyComment(roomId, parentCommentKey, data) {
  const parentComment = await base.fetch(`comments/${roomId}`, {
    asArray: true,
    queries: {
      equalTo: parentCommentKey,
      orderByKey: 'comments', // 'RIGHT? OR MAYBE orderByChild ?',
    },
  });

  return base.push(`${parentComment.<FULL_PATH_HERE, HOW?>}/comments`, {
    data,
  });
}
ridermansb
  • 10,779
  • 24
  • 115
  • 226
  • It's hard to see what your JSON looks like. Can you give a real snippet of JSON from your database? You can get this by clicking the "Export JSON" link in your [Firebase Database console](https://console.firebase.google.com/project/_/database/data). – Frank van Puffelen Nov 04 '17 at 16:01
  • I added an image – ridermansb Nov 04 '17 at 16:42
  • From the JSON you shared, there is no path `comments/${roomId}/comments`. There **is** a `comments/${roomId}/$someOtherPushId/comments`, but that's not what you're querying. I have a feeling you're trying to do the same as in this question: https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Nov 04 '17 at 19:03
  • Sorry, I fixed the code. – ridermansb Nov 04 '17 at 19:44

0 Answers0