I am wondering how to query only the keys of a data structure in Firebase.
I am currently doing this to search the website for the latest blogs:
const postsRef = firebase.database().ref('posts');
postsRef.once('value').then(postsObject => {
const titles = Object.keys(postsObject.val());
// ...
}
But it is obvious that it is inefficient as each time the user searches all of the posts, including their content, will be sent to the client when in fact I only need the titles of the posts.
For example, if this is my data structure I only need title 1
and title 2
:
- posts
- title 1 // I need this
- ... // I don't need this
- title 2 // I need this
- ... // I don't need this