Shivam Sahil
Shivam Sahil

Reputation: 4921

Realtime Database Web: Is it possible to only get values?

I have a realtime db entries as shown below:

{
        <FIREBASE_GENERATED_KEY>:{username:<NAME>,message:<TEXT>,time:<TIMESTAMP>},
        <FIREBASE_GENERATED_KEY>:{username:<NAME>,message:<TEXT>,time:<TIMESTAMP>},
        ...
}

I am interested in getting only the values ordered by time in descending order and displaying them on UI. In Admin SDK I would do something like:

rdb
      .ref(`${rdb_paths.funfuse_connected_users}/${loc}`)
      .orderByValue('time')
      .get()

I see there's a method orderByValue but It doesn't take any arguments. How can we use orderByValue or anything to just get values instead of the entire object?

Upvotes: 0

Views: 21

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599541

The Firebase Realtime Database always returns complete nodes from the JSON, or a set of complete child nodes that math a certain condition. There is no way to get a subset of the properties for each child node.

If you find yourself regularly needing only the time property of each child node, consider adding another branch to your database where you just keep the time values.

So:

"Original_data": {
        <FIREBASE_GENERATED_KEY>:{username:<NAME>,message:<TEXT>,time:<TIMESTAMP>},
        <FIREBASE_GENERATED_KEY>:{username:<NAME>,message:<TEXT>,time:<TIMESTAMP>},
        ...
},
"Times": {
        <FIREBASE_GENERATED_KEY>: <TIMESTAMP>,
        <FIREBASE_GENERATED_KEY>: <TIMESTAMP>,
        ...
}

Upvotes: 1

Related Questions