I am working with cloud functions. Initially, I am extracting data from a collection and then I have to add the same data to another document but I want to change to the timestamp to next month. Example - Old timestamp - 24 February 2022 at 03:00:00 UTC+5:30 The timestamp I want to add to a new collection - 24 March 2022 at 03:00:00 UTC+5:30 My code -
/* eslint-disable */
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
const database = admin.firestore();
exports.checkForPending = functions.pubsub.schedule('* * * * *').onRun(async
(context) => {
const query =
database.collection("users").doc('IELTS').collection('IELTS').where("next", '<=', admin.firestore.Timestamp.now());
const snapshot = await query.get();
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data().name);
database.collection('pending').add(doc.data());
});
return null;
});
Thank you in advance!