the firebase cloud function will change depending on the date

You’re storing Firestore timestamp’s in the database.

There are two problems with the code you shared:

  1. Your tommorow variable is a number (the number of milliseconds since the epoch). Since you store date/time in Firestore, you’re trying to compare a number with a date/time, which will never match.

  2. Since you’re storing a date/time, getting the documents for a day is a range operation. You want all documents between date/time A and date/time B.

If you want all documents with a date/time between now and 24 hours from now, that’d be:

const nowTimestamp = Date.now();
const now = new Date(nowTimestamp);
const tommorow = new Date(nowTimestamp + 24*60*60*1000);

firebase.firestore
  .collection("consultations")
  .where("date", '>=', now)
  .where("date", '<', tomorrow)

Another problem in your code that you’re trying to call set on a query, which is not possible. You’ll need to:

  1. Execute the query to get the documents that match it.
  2. Loop over the documents in your code.
  3. Update each document in turn.

For more on this, I recommend checking out: How to use where and update

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top