Trying to access message inputs from ALL users has been a challenge. While it can be done for a specific user, the goal is to do so for all users by specifying in the code. Each UID is unique, adding complexity to the process.
The Realtime Database structure currently looks like this:
-Realtime Database Tree-
--- chats ---
|
UID (unique) ---
|
email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d18051c100d11183d1011531e1210">[email protected]</a>
message: Hello World.
date: Tues Apr 16 2024
The current code snippet attempted is as follows:
const dbRef = ref(getDatabase());
get(child(dbRef, 'chats/')).then((snapshot) => {
if (snapshot.exists()) {
const snaps = snapshot.val();
console.log(snaps);
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
The objective is to retrieve and display email, message, and date information in the console log. While it's achievable with specific UID's like
get(child(dbRef, 'chats/specific_UID')).then((snapshot) => {
if (snapshot.exists()) {
const snaps = snapshot.val().message;
console.log(snaps);
The target now is to extract data within each UID including email, message, and date fields.
How can this be accomplished?