LoginSignup
0
1

More than 3 years have passed since last update.

Cloud Firestore でサーバーの現在時刻を保存する

Posted at

概要

Firebase の Cloud Firestore でサーバーの現在時刻を保存する方法を調べたので、ご紹介します。

Firestore でサーバーの現在時刻を保存するサンプルコード

結論としては、 require("firebase-admin").firestore.FieldValue.serverTimestamp() を利用すれば良いです。

以下、Node.js のサンプルコードです。

const admin = require("firebase-admin");
const db = admin.firestore();
const FieldValue = admin.firestore.FieldValue;

let docRef = db.collection('objects').doc('some-id');

let updateTimestamp = docRef.update({
  timestamp: FieldValue.serverTimestamp()
});

以上、Cloud Firestore でサーバーの現在時刻を保存したい、現場からお送りしました。

参考情報

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1