0

I am trying to use firebase serverTimestamp with nodejs

const Queue = require('firebase-queue');
const admin = require("firebase-admin");
const { Firestore } = require('@google-cloud/firestore');

const firestore = new Firestore();

    job.ref.update({
     timeProcessingEnded: admin.firestore().FieldValue.serverTimestamp(),
   })

Also tried:

admin.firestore.FieldValue.serverTimestamp(),

firestore.FieldValue.serverTimestamp(),

I get an error

Cannot read property 'serverTimestamp' of undefined

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user567
  • 3,712
  • 9
  • 47
  • 80
  • 1
    It's really not a good idea to mix `@google-cloud/firestore` with `firebase-admin`. The Admin SDK is just a wrapper around the google cloud SDK. If you want to use firebase-admin, you should just use its exported APIs exclusively, ignoring the exports from google cloud. This means you should follow the [documentation](https://firebase.google.com/docs/admin/setup) to initialize the Admin SDK. Also note in that documentation they are showing you different imports that what you're using now. – Doug Stevenson Apr 15 '23 at 16:21
  • It's `admin.firestore.FieldValue.serverTimestamp()`, so without parenthesis after `firestore`. – Frank van Puffelen Apr 15 '23 at 16:29

0 Answers0