I'm trying to fetch data from my Realtime database but when I do, it return my this object:
{"domain":{"domain":null,"_events":{},"_eventsCount":3,"members":[]}} instead of something like this: {0: 'user1', 1: 'user2'}.
There is a screen from my Realtime database:
My code:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.getProductTypeUpdate = functions.database
.ref("Products/{product}/type")
.onUpdate((snapshot, context) => {
const type = snapshot.after.val();
console.log("Product type created: " + type);
const users = admin.database().ref("Notif/type/" + type)
.once("value").then((snapshot) => {
return snapshot.val();
}).catch((error) => {
console.log("Error sending message:", error);
return false;
});
console.log("Users fetched are: " + JSON.stringify(users));
const result = {etat: "create", users: users};
console.log("Final result is: " + JSON.stringify(result));
return result;
});
And the "error" (it's write in french but it's not important):
Thank you for help !