最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to use FieldValue.serverTimestamp() in Firebase Firestore JS without Firebase-Admin - Stack Overfl

programmeradmin0浏览0评论

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 ?

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 ?

Share Improve this question asked Oct 24, 2017 at 14:58 le0le0 8512 gold badges9 silver badges22 bronze badges 3
  • 4 FieldValue.serverTimestamp() available in all client SDKs, including Javascript. – Bob Snyder Commented Oct 24, 2017 at 15:06
  • @BobSnyder Thanks. It worked. – le0 Commented Oct 24, 2017 at 16:00
  • yeah using this solves it in your object to add: firebase.firestore.FieldValue.serverTimestamp() – Leonardo G. Commented Aug 4, 2018 at 11:14
Add a comment  | 

4 Answers 4

Reset to default 9

https://firebase.google.com/docs/reference/js/firestore_.md#servertimestamp

import { serverTimestamp } from "firebase/firestore";

addDoc(collection(db, 'your_collection'), {
  ...
  createdAt: serverTimestamp()
})

you can get the instance from your firebase instance:

firebase.firestore.FieldValue.serverTimestamp();

try to import firebase like this -

import firebase from "firebase/compat/app";

This answer is outdated, check above answer!

Simply use Firebase.ServerValue.TIMESTAMP within your object.

Like this:

ref.set({ time: Firebase.ServerValue.TIMESTAMP })

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论