gpt4 book ai didi

node.js - 如何从 Firebase Cloud Function 访问 firestore.Timestamp

转载 作者:搜寻专家 更新时间:2023-11-01 00:04:14 29 4
gpt4 key购买 nike

我们正在将我们的 Firestore 日期对象转换为新的 Timestamp Objects

我们通过导入 firestore 在前端成功地做到了这一点

import { firestore } from 'firebase';

然后用 firestore.Timestamp 替换所有 Date 对象类型

  startDate: firestore.Timestamp;

问题是我似乎无法找到一种方法来访问 Node 中的时间戳。

我已经尝试记录 admin 和 functions 对象,但似乎根本找不到时间戳

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
...
console.log(functions)
console.log(admin)

这些是我尝试过的,它们都返回了“未定义的时间戳不存在”

import * as firebase from 'firebase';
...
firebase.firestore.Timestamp.now()

const firebase = require('firebase')   
...
firebase.firestore.Timestamp.now()

import * as admin from 'firebase-admin';
...
admin.firestore.Timestamp.now()

这是我的 package.json 依赖项

"dependencies": {
"@sendgrid/mail": "^6.2.1",
"@types/node-fetch": "^1.6.8",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"cors": "^2.8.4",
"encodeurl": "^1.0.2",
"fetch": "^1.1.0",
"firebase": "^4.13.0",
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1",
"generator-karma": "^2.0.0",
"google-distance": "^1.0.1",
"mailgun-js": "^0.13.1",
"moment": "^2.22.1",
"node-fetch": "^2.1.2",
"request": "^2.85.0",
"sinon": "^4.0.1",
"typescript": "^2.8.3"
},
"private": true,
"devDependencies": {
"@angular/cli": "^1.7.4",
"@types/cors": "^2.8.3",
"@types/jasmine": "^2.6.6",
"ts-loader": "^3.5.0",
"webpack-node-externals": "^1.7.2"
}

最佳答案

随着 Firebase Functions V2.0 的发布,他们似乎已经在 Firebase Admin SDK 包中添加了时间戳支持。

看看官方文档here .

import { firestore } from 'firebase-admin';
...
const now = firestore.Timestamp.now()

关于node.js - 如何从 Firebase Cloud Function 访问 firestore.Timestamp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50580014/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com