I have a managed workflow expo project (Javascript 9) where I want to read my data from Firebase database. I succesfully managed to implement firestore but the database is giving me rough times.
This is my code to Fecth the data:
export const fetchEmployees = async () => {
const rootRef = await dbref(db_realtime,"Employees");
const query = get(query(child(rootRef))).then((result) =>{
console.log(result)
})
}
This is the warning I get:
[Unhandled promise rejection: Error: child failed: path argument was an invalid path = "undefined". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"]
And this is how the data looks like in my Firebase Database storage:
Hope this example will help you. It will return all employees details -
const getdata = await db.ref('Employees').once('value',function(snapshot){
console.log(snapshot.val)
}
Here db is your firebase.database().
If it's not working use 'Employees/'.
EDITED -
For 9 -
import { getDatabase, ref, onValue} from "firebase/database";
const db = getDatabase();
const employeeRef = ref(db, 'Employees');
onValue(employeeRef , (snapshot) => {
console.log(snapshot.val());
});