...

/

Read, Write, and Delete Data from the Realtime Database

Read, Write, and Delete Data from the Realtime Database

Learn to read and write data to the Realtime Database and discover different ways to perform read and write operations.

To carry out any operation on the Realtime Database, we must create a reference to the specific path within our database. To do this, we use the ref function, imported from the firebase/database subpackage. This function returns a reference to the location in the database that corresponds to the provided path.

The ref function takes the database instance as its first argument. It can also optionally take the path that the returned reference points to, as its second argument. However, if no path is provided, the function returns a reference to the root of the database:

Press + to interact
import { getDatabase, ref } from "firebase/database";
// initialise database
const db = getDatabase();
// reference to database root
const dbRef = ref(db);
// reference to the users/tasks/* path
const tasksRef = ref(db, "users/tasks/" + user.uid);

Basic write operations

We use ...