0

What strategy should I choose for getting all of 2-depth firebase data (if possible, not multiple queries)? Let's say the data are memos of my-added-content and I want to get them by createdAt.

In firebase database, the memo structure is here:

{
  "memos": {
    "uid1": {
      "contentId1": {
        "memoId123": {
          "memoBody": "I want to write A",
          "createdAt": 10,
          ...
        },
        "memoId213": {
          "memoBody": "I want to write B",
          "createdAt": 12,
          ...
        }
      },
      "contentId2": {
        "memoId312": {
          "memoBody": "I want to write C",
          "createdAt": 11,
          ...
        },
        "memoId321": {
          "memoBody": "I want to write D",
          "createdAt": 13,
          ...
        }
      }
    }
  }
}

What I want the result expected:

{
  "memoId123": {
    "createdAt": 10
    ...
  },
  "memoId312": {
    "createdAt": 11
    ...
  },
  "memoId213": {
    "createdAt": 12
    ...
  },
  "memoId321": {
    "createdAt": 13
    ...
  }
}

I thought it could be possible that brackets are used in string of ref:

firebase.database().ref('/memos/myuid/{contentId}').orderByChild('createdAt')

But this way is not worked.

Jinyoung Kim
  • 1,885
  • 3
  • 14
  • 23
  • 1
    Firebase queries work only across one dynamic level. If you want a list of memos, you should consider storing a list of memos (or memo ids). See https://stackoverflow.com/questions/27207059/firebase-query-double-nested – Frank van Puffelen Jul 18 '17 at 13:58
  • @FrankvanPuffelen Thanks for the comment. I'll try to denormalize memos. – Jinyoung Kim Jul 18 '17 at 15:09

0 Answers0