4

Is there a way to filter down which properties of each child I want to bring back inside of ref.on("value", ...)?

Let's say I have the structure on https://www.firebase.com/docs/data-structure.html, but in addition to name, each user also has a list of every line of chat he has produced. How can I bring back only the name?

1 Answer 1

3

UPDATE: As of Firebase 2.0, you can now query based on fields.

There isn't currently a way to pick data out of a path (i.e. filter which fields you get back). The easiest solution here is to store the data in different paths. It greatly simplifies the process.

users/
users/names/fred/first
users/chat_history/fred/...

Another useful approach, particularly when you're going to be using a lot of subsets (e.g. friends list, members of a group, et al) is to use an index.

user_index/group_1/fred
user_index/group_1/mary
user_index/group_2/...

users/fred/name
users/fred/chat_history

Then you can access the data with something like this:

var fb = new Firebase(INSTANCE);
fb.child('user_index').on('child_added', function(ss) {
   fb.child('users/'+ss.name()+'/name').once('value', function(nameSnapshot) {
      var userName = nameSnapshot.val();
   });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.