1

Is there something equivalent to firebase.database.TIMESTAMP for Firebase Firestore ?

I would like that the timestamp of a field be determined by the Firebase servers in a write operation.

le0
  • 791
  • 2
  • 8
  • 19
  • See also: https://stackoverflow.com/a/46855006/4815718 – Bob Snyder Oct 24 '17 at 00:56
  • @BobSnyder The FieldValue.serverTimestamp() only exists in firebase-admin (according to Frank van Pufflen answer), that requires server. I am using Web SDK, that runs in Browsers. Is there any way to use it in Firebase JS ? – le0 Oct 24 '17 at 14:50
  • 3
    `FieldValue.serverTimestamp()` available in all client SDKs, [including Javascript](https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue). – Bob Snyder Oct 24 '17 at 15:04
  • @BobSnyder Thanks. It worked. – le0 Oct 24 '17 at 16:01
  • This question is _not_ a duplicate of [How do I get the server timestamp _in Cloud Functions_ for Firebase with Firestore?](https://stackoverflow.com/q/46647964/2054731). This question is about how to solve it in javascript (like in a Web application), which the other question does not ask about, nor has it received any answers telling us how to do it. This question should be reopened, so a "right answer" similar to @BobSnyder's 2nd comment, above, can be posted. – ArneHugo May 04 '18 at 17:20

1 Answers1

0

When you are using

ServerValue.TIMESTAMP

You are fetching the timestamp from firebase db irrespective of which database you use either firestore or realtime database.

Kumar Vivek
  • 351
  • 7
  • 30
  • When I tried using `firebase.database.ServerValue.TIMESTAMP` in Firestore, I just got an object like this: `{ sv: "timestamp"}`, so unless I made some other mistake it is not usable in Firestore. – ArneHugo May 04 '18 at 16:58
  • Instead, use `firebase.firestore.FieldValue.serverTimestamp()`. It is the equivalend for Firestore. – ArneHugo May 04 '18 at 17:15