Is there a way to get a list of keys of all child nodes (either once or with an open connection), without transferring all the data for those child nodes?
Asked
Active
Viewed 5,565 times
1 Answers
8
The Firebase JavaScript SDK always retrieves complete nodes, so there is no way to read only the keys.
The Firebase REST API has a parameter shallow=true
that will retrieve only the keys under the location. See https://firebase.google.com/docs/database/rest/retrieve-data#shallow
If you don't want to use the REST API, you'll have to restructure your data to allow for the query you want. It is quite common in NoSQL data stores to maintain you own indexes, just for such queries.
E.g.
/users
"12-ad-b3-ad"
name: "Frank van Puffelen"
stackoverflowId: 209103
bio: "auihodasiuodsa ohdsau duia hdsauhio aoi das"
avatarUrl: "https://www.gravatar.com/avatar/12d378e6a9788ab9c94bbafe242b82b4?s=48&d=identicon&r=PG"
"18-a7-12-86"
name: "Linda H"
stackoverflowId: 3243018
bio: "as ihuew rew i noiueh ewo we weru irew ure oew"
avatarUrl: "https://i.stack.imgur.com/0lcm6.jpg?s=32&g=1"
/uids
"12-ad-b3-ad": true
"18-a7-12-86": true
/stackoverflowIds
209103: "12-ad-b3-ad"
3243018: "18-a7-12-86"

Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
1Thanks for the info. I may have to mix REST with the JS SDK as I'd like to keep denormalization/duplication to a minimum. – Linda H Sep 07 '15 at 17:05
-
2The REST implementation on that page has been deprecated - is there a supported way to do it today? – fmacdee Mar 13 '17 at 22:45