问题
According to answer below, Firebase-Admin is required to use FieldValue.serverTimestamp().
How do I get the server timestamp in Cloud Functions for Firebase with Firestore? .
But I am using only Firebase JS and Firebase Firestore JS. The application runs only in client side. However, Firebase-Admin requires a server.
Is there any way to use server timestamp when doing a write operation ?
回答1:
Simply use Firebase.ServerValue.TIMESTAMP
within your object.
Like this:
ref.set({ time: Firebase.ServerValue.TIMESTAMP })
回答2:
you can get the instance from your firebase instance:
firebase.firestore.FieldValue.serverTimestamp();
来源:https://stackoverflow.com/questions/46913824/is-there-any-way-to-use-fieldvalue-servertimestamp-in-firebase-firestore-js-wi