We are in the middle of converting our Firestore Date object to the new Timestamp Objects
We have done so successfully on the front end by importing firestore
import { firestore } from 'firebase';
and then replacing all Date object types with firestore.Timestamp
startDate: firestore.Timestamp;
The problem is I can't seem to find a way to get access to Timestamp in node.
I have tried logging both the admin and functions object but cant seem to find Timestamp at all
import * as functions from 'firebase-functions'; import * as admin from 'firebase-admin'; ... console.log(functions) console.log(admin)
These are what I've tried and they have all returned with 'Timestamp does not exist on undefined'
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()
Here are my package.json dependancies
"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" }
With the release of V2.0 of Firebase Functions is looks like they've added Timestamp support in the Firebase Admin SDK package.
Have a look at the official docs here.
import { firestore } from 'firebase-admin'; ... const now = firestore.Timestamp.now()
At this very moment in time, Timestamp is simply not available in the latest version of the @google-cloud/firestore
npm module for node. You can also see that it's not included in the API docs. Perhaps it will be added in the next release of @google-cloud/firestore
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With