Complete the code to import the Realtime Database module from Firebase.
import { getDatabase } from '[1]';
You import getDatabase from firebase/database to use Realtime Database features.
Complete the code to get a reference to the Realtime Database.
const db = [1]();getDatabase() returns the Realtime Database instance to read or write data.
Fix the error in the code to write data to the Realtime Database.
import { ref, set } from 'firebase/database'; const db = getDatabase(); set([1](db, 'users/user1'), { username: 'Alice' });
The correct function to create a reference is ref. Other names cause errors.
Fill both blanks to read data once from the Realtime Database.
import { ref, [1] } from 'firebase/database'; const db = getDatabase(); [2](ref(db, 'messages/message1')).then(snapshot => { if (snapshot.exists()) { console.log(snapshot.val()); } });
The get function reads data once from the database. It returns a promise.
Fill all three blanks to listen for real-time updates on a database reference.
import { ref, [1] } from 'firebase/database'; const db = getDatabase(); const messageRef = [3](db, 'chat/latest'); [2](messageRef, snapshot => { console.log(snapshot.val()); });
ref creates the reference, and onValue listens for real-time updates.
