firebase / firebase/firebase-js-sdk
FR: new option for FieldValue.serverDateMs
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
Hi, I know that Firestore already supports `serverTimestamp`. However, I would like to request an additional option `serverDateMs`, which allows the server to set a field with the date value in milliseconds.
Here are some benefits of `serverDateMs`:
- It's intuitive: the value is just a number and everyone knows how to query on the number column.
- It's simple: the number can be saved directly to any local database on all platforms, it can be easily converted to JSON or any other data format. The `Timestamp` requires additional processing before it can be saved to the local database or converted to JSON.
- It's convenient: number can be converted to `Date` object on any platform. The `Timestamp` object, while providing nanoseconds, is generally not needed in most programming languages, which only support milliseconds.
In my project, I cannot use `serverTimestamp` because the older version of the app cannot handle `Timestamp` object and crash. To set `serverDateMs`, I have to use Cloud Firestore trigger, make sure the function is idempotent and doesn't cause an infinite loop, carefully avoid the database transaction contentious error in case the trigger is executed multiple times. This is difficult and pretty inefficient.
As for the implementation, I think it would not be difficult since `serverDateMs` is very similar to `serverTimestamp`.
I really hope that `serverDateMs` is considered as it would be a huge improvement for my project and possibly many others.
Thank you for listening!
Contributor guide
Assessment
This issue has not been assessed yet.