0

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!

Rishi
  • 11
  • 5
  • There is nothing Firestore or Cloud Functions specific about this, so I recommend having a look at [how to add a month to a javascript date](https://www.google.com/search?q=how+to+add+a+month+to+a+javascript+date). – Frank van Puffelen Feb 23 '22 at 19:01
  • Also note that this has nothing to do with Flutter, but is all about JavaScript. While you may be using Flutter in your app, it helps if you only tag your question with the tags that are relevant to the problem you're asking about. – Frank van Puffelen Feb 23 '22 at 19:03

0 Answers0