You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⭐️ 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 method 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:
❓ 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.)
The set method saves data to a specified location in the database (using a database Reference object). If that database location doesn't exist yet, the set method will create it! Otherwise, if data already exists there, the set method will replace it with the new data. If that database location contains any children (nested objects), they will all be overwritten with the new data.
Your challenge
🏆 The goal: learn how this method 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 method?
When would we need to use this method? What are some example use cases? (Write some sample code for us, please!)
When should we not use this method? Can you think of any scenarios where using this method would cause errors or unintended side effects?
How many inputs does this method require, if any? What data types can the inputs be?
What does this method return as an output, if any? What data type is returned?
If there are different options for inputs, how does this method behave differently depending on the different possible input(s)?
The text was updated successfully, but these errors were encountered:
LearningNerd
changed the title
Up for grabs: Create an example of the Firebase set method to insert or update data
Up for grabs: Create an example of the Firebase set() method
Jun 15, 2017
Overwrites data at parent and child location.
Does not require inputs -> void function
Returns promises
How they are different :
Overwrites data and doesn't have hierarchy, so you have to be careful when using this function
If you'd like to have a starting and stopping point for setting data, to ensure that your data
isn't overwritten (or up to a certain point), you should use setWithPriority()
set() generates a value, and a promise upon completion
Example of using Set
(Set by individual value)
var dataRef = firebase.database().ref('/users/name');
dataRef.child('first').set('Bob')
(Set simultaneoulsly)
var dataRef = firebase().ref({first : 'Bob', last: 'Smith'});
return promise to see whether the information has been set
successfully or not in the database
.then(function() {
console.log("Success!")
})
.catch(function(e){
console.log("Failed to set data" + e); // failed and log error
});
Thanks @kammitama5!! The second example code snippet ("set simultaneously") looks like it's missing the call to set() though, and I also notice you set the variable dataRef equal to the result of setting the new data but you probably meant to first create the database reference, and then set the new data. So maybe more like:
For the last code snippet, you'll need to add something at the beginning because right now there's no Promise object before the .then -- although I wouldn't worry about using or explaining how to use Promises just yet here!
Another awesome addition to your answers would be to create your own CodePen with a working example to demonstrate using the set() method! :)
⭐️ 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 method 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:

❓ 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
set
method📚 Official documentation: Firebase API section on the
set
methodThe
set
method saves data to a specified location in the database (using a database Reference object). If that database location doesn't exist yet, theset
method will create it! Otherwise, if data already exists there, theset
method will replace it with the new data. If that database location contains any children (nested objects), they will all be overwritten with the new data.Your challenge
🏆 The goal: learn how this method 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:
The text was updated successfully, but these errors were encountered: