Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up for grabs: Create an example of the Firebase "key" property #54

Open
LearningNerd opened this issue Jun 15, 2017 · 2 comments
Open

Comments

@LearningNerd
Copy link
Member

⭐️ This challenge is up for grabs! Claim it by clicking "assign yourself" on the right, under the "Assignees" section for this GitHub issue! You can work on this by yourself or in pairs.

✔️ To complete this challenge: Post a comment at the bottom of this page with some instructions and sample code, so the rest of our team can learn how to use this new Firebase property by reading your comment!

You can edit your comment at any point to update your answer, so you don't have to do these all at once! To edit your comment after you publish it, click the pencil icon in the top right corner of your comment:
github-edit-comments

If you have any questions, please post a comment at the bottom of this page! (You can also ask us on Slack, but please post a comment here too so we can more easily reference it later.)

About the Firebase key property

📚 Official documentation: Firebase API section on the key property

Every database Reference object in Firebase has a key, except for the root of the database.

Your challenge

🏆 The goal: learn how this property works, test it out for yourself, and then post a comment at the bottom of this page with some instructions and sample code to help teach the rest of our team!

Questions to keep in mind:

  • What does the official documentation say about this property ?
  • When would we need to use this property ? What are some example use cases? (Write some sample code for us, please!)
  • When should we not use this property ? Can you think of any scenarios where using this property would cause errors or unintended side effects?
  • What data types can be stored as values of this property?
@kammitama5
Copy link
Collaborator

kammitama5 commented Jun 18, 2017

The key can be null or non-null
The key is used for accessing data at the end of the path.
You can find it by accessing the last item after the last "/"

for example,

var dbRef = firebase.database().ref("path/key");

Here, your key would be "key";

If you have no key (ie the reference is null),
it would look like :

var dbRef = firebase.database().ref();

@LearningNerd
Copy link
Member Author

Great start @kammitama5! Try refining this description and the example code some more when you have a chance -- right now your example isn't actually use the key property. For example, see the sample code in the official documentation:

// The key of any non-root reference is the last token in the path
var adaRef = firebase.database().ref("users/ada");
var key = adaRef.key;  // key === "ada"
key = adaRef.child("name/last").key;  // key === "last"

So the key property is used in adaRef.key to get the key (or path) of that database location, which is the string "ada" in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants