-2

I am implementing Firebase Realtime Database for my app. The database contains a lot of entries that will continue to grow in the future. I want to retrieve only a specific child from the database, but i can't find any implementation for doing that. In Firebase too the implementation retrieves all the entries from the database. This will be cumbersome in the future. Is there any way to retrieve only specific entries or just one entry(depending upon the customisation)?

Please help.

@ALex Mamo: This is the database image

Community
  • 1
  • 1

3 Answers3

0

Perhaps you are refering to shallow query, which only read the first child ? In this case you might want to look at the API implementation as mentioned here:

Firebase (2016) Shallow Query

Linh
  • 418
  • 4
  • 9
0

There are two different ways of getting it. You'll have to change 'messages' to the name of your database. Replace PostTitle with the specific data you're trying to receive.

var rootRef = firebase.database().ref().child("messages");

rootRef.on("child_added", snap=> {

  var postTitle = snap.child("PostTitle").val();

or

exports.sendPushNotification = functions.database.ref('/messages/{id}').onWrite((change, context) => {

    const afterData = change.after.val();
    const postTitle = afterData.PostTitle;
0

if you want retrieve few records this might help. as per image structure attached.

you can restructure the data, and use set method with keys as 0,1,2.... instead of "LK34h...."->0 . use set method and store latest index value.

you retrive like this

firebase.database().ref().child('users_Post/0').on('value',sn=>{ console.log(sn.val())//use sn.val() })