Reputation: 145
Is there any way to create new records with current timestamp (+ one hour)? And is it possible to select only the records with greater timestamp than now?
Upvotes: 1
Views: 105
Reputation: 2290
You can use client time in firebase.
OR
Use Cloud Functions for Firebase that lets you run mobile backend code that automatically responds to events triggered by Firebase features in your case the databas-events
See: https://firebase.google.com/docs/functions/database-events
Eg: Listens for /records/{pushId}/time and write time in /records/{pushId}/servertime
exports.makeUppercase = functions.database.ref('/records/{pushId}/time')
.onWrite(event => {
var date = new Date();
var current_hour = date.getHours();
return event.data.ref.parent.child('servertime').set(current_hour);
}
Also See: https://www.youtube.com/watch?v=7E13ZBCyKT0
Upvotes: 1
Reputation: 599491
There is no built-in operator for the server-side timestamp in queries. You'll have to build something using the client-side timestamp and the known latency to the server or read a server-side timestamp first.
Upvotes: 1