Reputation: 5758
I'm trying to query for data that's more then 8 hours old.
My data is stored like this:
{
"users": {
"user 1": {
"beginTime": 1576754815639,
//more data
},
"user 2": { ... },
"user 3": { ... }
}
}
I'm using the firebase admin sdk (for use with a cloud function) I found this example on their website.
var ref = db.ref("dinosaurs");
ref.orderByChild("height").startAt(3).on("child_added", function(snapshot) {
console.log(snapshot.key);
});
But I have no idea if I need "child_added" or how to implement startAt with the time.
How can I query for timestamps that are 8 (or more) hours old?
Thanks in advance for the help and effort!
Upvotes: 1
Views: 521
Reputation: 80904
You can do the following:
var ref = db.ref("users");
ref.orderByChild("beginTime").startAt(1576754815639).on("value", function(snapshot) {
console.log(snapshot.key);
console.log(snapshot.val());
});
Add a reference to node users
then using orderByChild
to query and attach a value
event to the query to retrieve the data
Check the docs:
https://firebase.google.com/docs/database/admin/retrieve-data
Upvotes: 2