Firestore中的serverTimestamp()返回ServerTimestampTransform

时间:2019-10-08 06:42:55

标签: firebase google-cloud-firestore timestamp firebase-admin

以下代码突然返回ServerTimestampTransform而不是实际的服务器时间戳

admin.firestore.FieldValue.serverTimestamp()

我正在使用Firebase-admin的最新版本8.6.0 https://www.npmjs.com/package/firebase-admin

关于此的任何想法

-Jani

1 个答案:

答案 0 :(得分:1)

这是示例在github代码中概述的内容

/**
   * Returns a sentinel used with set(), create() or update() 
 to include a
   * server-generated timestamp in the written data.
   *
   * @return {FieldValue} The FieldValue sentinel for use in 
 a call to set(),
   * create() or update().
   *
   * @example
   * let documentRef = firestore.doc('col/doc');
   *
   * documentRef.set({
   *   time: Firestore.FieldValue.serverTimestamp()
    * }).then(() => {
    *   return documentRef.get();
    * }).then(doc => {
    *   console.log(`Server time set to ${doc.get('time')}`);
   * });
   */
  static serverTimestamp(): FieldValue {
    return ServerTimestampTransform.SERVER_TIMESTAMP_SENTINEL;
 }