Reputation: 24560
I am using push to add data to a list at a certain location, I will need to analyze the list I've got with respect to the time at which each item was pushed.
Do I have to store timestamp in the inserted object to be able to do a time based query? ex: get all items between time x and time y
I want to make sure I am doing it right, as Firebase already uses timestamp to guarantee unique key for each pushed item
{
data:"Data to be stored",
timestamp: /* time at which the data was pushed, is this important to do time-based query? */
}
Upvotes: 2
Views: 1081
Reputation: 598765
If you want to query on the timestamp, you should indeed store the timestamp. While technically it is possible to extract the timestamp from Firebase's push ids, you should not rely on doing so.
Note that you'll have another choice to make for what value to store. Do you want to store when the user sends the data (in JavaScript Date.now()
) or when the server stored the data (using Firebase.ServerValue.TIMESTAMP
). There will always be some difference between these values. But when the user loses network connectivity, the difference can become huge. It's up to you to determine what logic you need for your use-case.
Upvotes: 2