Nikos
Nikos

Reputation: 7552

How to update data in Firebase realtime database using Firebase 9 (modular sdk)

How do we do this now:

import "firebase/database"

await firebase
        .database()
        .ref('users/' + auth.currentUser.uid)
        .update({
            displayName: displayName
        });

Upvotes: 4

Views: 3066

Answers (1)

Dharmaraj
Dharmaraj

Reputation: 50830

That should do:

import firebase from "firebase/compat/app";
import {update, ref, getDatabase} from "firebase/database"

const app = firebase.initializeApp(firebaseConfig);

const db = getDatabase(app)
const dbRef = ref(db, `users/{userUid}`)
update(dbRef, {displayName: "Firebase9_IsCool"}).then(() => {
  console.log("Data updated");
}).catch((e) => {
  console.log(e);
})

Upvotes: 9

Related Questions