I'm updating my database with Firebase Admin SDK like so:
admin.database().ref(`clients/${id}`).update({name: 'name'})
.then(snapshot => console.log(snapshot))
However, it logs undefined
. Any ideas why this could be?
"firebase-admin": "^9.12.0"
CodePudding user response:
This is because the Promise returned by the update()
method does not contain the snapshot of the node you've just updated.
You need to re-query the RTDB to get the value of the node, as follows:
const dbRef = admin.database().ref(`clients/${id}`);
dbRef.update({name: 'name'})
.then(() => {
return dbRef.get();
})
.then(snapshot => {
console.log(snapshot.val());
})