【问题标题】:how to set server time stamp with firestore admin nodejs sdk?如何使用firestore admin nodejs sdk设置服务器时间戳?
【发布时间】:2018-06-10 23:18:32
【问题描述】:
const firebase = require('@firebase/app').default;
require('@firebase/firestore')

const admin = require('firebase-admin')
const functions = require('firebase-functions')

// initialize the admin SDK...    

exports.setUpdatedDate = functions.firestore.document('/foos/{fooId}/bars/{barId}')
    .onCreate(event => {
      admin.firestore().collection('foos').doc( event.params.fooId )
            .set({
                updatedDate: firebase.firestore.FieldValue.serverTimestamp()
            }, {merge:true})
    })

运行上面的函数shell,我得到了:

Cannot encode type ([object Object]) to a Firestore Value
at Function.encodeValue (...\functions\node_modules\@google-cloud\firestore\src\document.js:772:11

那么如何使用 firestore admin nodejs sdk 设置服务器时间戳?

【问题讨论】:

  • 您似乎没有初始化管理 SDK。此外,您似乎需要客户端 SDK。这些不适用于 Cloud Functions。你只需要firebase-admin。
  • @DougStevenson thx,我确实做到了,只是没有发布。 :)

标签: node.js firebase google-cloud-functions google-cloud-firestore firebase-admin


【解决方案1】:

【讨论】:

  • 谢谢!您认为更新最后更新日期最好通过云功能或客户端事务完成?
  • 我觉得这是应该随着客户事务更新的东西。
  • 使用链接失效
  • 我目前正在使用这个函数,它返回一个空值
猜你喜欢
  • 2019-11-26
  • 1970-01-01
  • 2020-11-17
  • 2018-10-24
  • 2018-11-27
  • 2021-04-19
  • 1970-01-01
  • 2020-10-24
  • 1970-01-01
相关资源
最近更新 更多