I'm having a tough time sorting data in the real-time database. I've been following the documentation and implementing the steps exactly, but so far, nothing seems to be working. I expected it to work similarly to filtering, which is functioning well, but unfortunately, I'm not seeing any positive results.
Below is the code snippet for my React Native project:
useEffect(() => {
onValue(
// Order by the "createAt" field
query(
ref(db, "deals/"),
orderByChild("createAt"),
startAt("2023-12-31 23:59:59")
),
(snapshot) => {
setData(snapshot.val());
},
(err) => {
console.error(err);
}
);
}, []);
I've experimented with different sorting functions like orderByChild(), orderByKey(), and orderByValue(). I even tried changing the field type to both 'number' and 'string', but I'm still unable to find a solution that works.