Complete the code to read data once from Firebase Realtime Database.
firebase.database().ref('users').[1](snapshot => { console.log(snapshot.val()); });
The once method reads data a single time from the database.
Complete the code to listen for real-time updates on the 'messages' node.
firebase.database().ref('messages').[1]('value', snapshot => { console.log(snapshot.val()); });
The on method sets up a listener for real-time updates.
Fix the error in the code to properly remove the listener.
const ref = firebase.database().ref('tasks'); ref.on('value', snapshot => { console.log(snapshot.val()); }); // Remove listener ref.[1]('value');
The off method removes listeners previously attached with on.
Fill both blanks to read data once and handle errors.
firebase.database().ref('profiles').[1]('value').then(snapshot => { console.log(snapshot.val()); }).[2](error => { console.error(error); });
Use once to read data once, and catch to handle errors in the promise.
Fill all three blanks to listen for child added events and log the new child's key and value.
firebase.database().ref('notifications').[1]('child_added', snapshot => { const key = snapshot.[2]; const value = snapshot.[3](); console.log(key, value); });
Use on to listen continuously, key to get the child's key, and val() to get its value.
