Get timestamp field from snapshot as Timestamp inside Cloud Function Triggers

Get timestamp field from snapshot as Timestamp inside Cloud Function Triggers

In typescript, I can create document with field like createdAt, updatedAt as Timestamp by using&nbsp;<code>change.after.updateTime</code>&nbsp;or&nbsp;<code>snap.createTime</code>&nbsp;inside Cloud Functions Triggers.

In typescript, I can create document with field like createdAt, updatedAt as Timestamp by using change.after.updateTime or snap.createTime inside Cloud Functions Triggers.

But inside other triggers like onUpdate, the field change.after.data().updatedAt that suppose to store a Timestamp, gives me an object.

How can i compare them if i can't get them as Timestamp value ? How can i get the field as Timestamp value ? Thanks

admin.initializeApp();
const firestore = admin.firestore();
const settings = { timestampsInSnapshots: true };
firestore.settings(settings);


export const setCreatedAt = functions.firestore.document('path') .onCreate(async (snap, context) => {

    return snap.ref.update({
        createdAt: snap.createTime, // Type Timestamp
        updatedAt: snap.createTime // Type Timestamp
    });

});

export const setUpdatedAt = functions.firestore.document('path') .onUpdate(async (change, context) => {

    let beforeTimestamp = change.before.data().updatedAt; // Type object, not Timestamp
    let afterTimestamp = change.after.data().updatedAt; // Type object, not Timestamp

    console.log('beforeTimestamp', beforeTimestamp);
    console.log('afterTimestamp', afterTimestamp);

    if (change.before.data().updatedAt === change.after.data().updatedAt) {
        change.after.ref.update({
            updatedAt: change.after.updateTime, // Type Timestamp
        });
    }
});

The image below shows the logs when doing an update. 

It looks like the { timestampsInSnapshots: true } settings has no effect because i still have the warning inside the console. But why ?

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK


typescript firebase

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

What is firebase,firebase bangla tutorial.

LIKE | COMMENT | SHARE | SUBSCRIBE The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in re...

Firebase Introduction with C#

LIKE | COMMENT | SHARE | SUBSCRIBE Firebase is a mobile and web application development platform developed by Firebase, Inc. in 2011, then acquired by Google...

Create database into firebase

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, I will show you how to Create database into #firebase console. Subscribe & Stay Connected! Thank You! ♥ #Fi...

Save Employee into firebase

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, I will show you how to save employee information into firebase database. Subscribe & Stay Connected! Thank ...

How to Initialize Firebase in Rollup + TypeScript

If you are building a JavaScript library or an app using TypeScript and Rollup, you probably have an issue importing Firebase in your code…