简体   繁体   中英

How to retreive the child Nodes keys only Firebase?

在此处输入图像描述

Actually i am fetching the data of all the subjects to the listView

which are Pathology and SocialScience.

when i am retreiving the key i am getting ending date, starting date all that too.

How can i get the only the children which have nodes like here pathology and Soil scence. ?

When you retrieve a node with Firebase, it always retrieves the entire node. There is no way to get a node without its children, or (beyond what a query can do) with a subset of its children.

When you have this need, it typically means that you've mixed two types of data in a single branch. The Firebase documentation recommends avoiding such data nesting .

In your case, I'd split the data into two top-level nodes, each with the same keys for its children. Something like:

ExamInfos: {
  "-MV8_...": {
    "endingDate": ...,
    "examType": ...,
    "programme": ...,
    "startingDate": ...
  }
},
ExamSugbjects: {
  "-MV8_...": {
    "PATHOLOGY": { ... },
    "SOIL SCIENCE": { ... }
  }
}

Now you can get all subjects for an exam, by loading its ExamSubjects child node, all other info by loading its ExamInfos child node, and you can load both if needed. Contrary to what many devs initially expect, this won't take much more time, as Firebase can pipeline the requests over its existing web socket connection .


As a separate recommendation, I'd also consider storing the dates in a format that allows more ordering and filtering. The most common format for this is 2021-03-07 for March 7, 2021.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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