Complete the code to write data to a Firebase Realtime Database using the set method.
firebase.database().ref('users/user1').[1]({ name: 'Alice', age: 30 });
The set method writes data to the specified database reference, replacing any existing data.
Complete the code to update only the age field of a user in Firebase Realtime Database.
firebase.database().ref('users/user1').[1]({ age: 31 });
The update method modifies only the specified fields without overwriting the entire data at the reference.
Fix the error in the code to add a new message to the messages list using push.
firebase.database().ref('messages').[1]({ text: 'Hello', timestamp: Date.now() });
The push method adds a new child node with a unique key under the specified reference.
Fill both blanks to update the user's email and add a new phone number using push.
const userRef = firebase.database().ref('users/user2'); userRef.[1]({ email: 'user2@example.com' }); userRef.child('phones').[2]('123-456-7890');
Use update to change the email without overwriting other data, and push to add a new phone number as a child with a unique key.
Fill all three blanks to set a new post, update its title, and add a comment using push.
const postRef = firebase.database().ref('posts/post1'); postRef.[1]({ title: 'First Post', content: 'Hello world!' }); postRef.[2]({ title: 'Updated Post Title' }); postRef.child('comments').[3]({ text: 'Nice post!' });
First, set creates the post. Then, update changes the title without removing content. Finally, push adds a new comment with a unique key.