Home > Blockchain >  Firestore get all Documents between two dates
Firestore get all Documents between two dates

Time:12-03

query(meetingsCollection, where("start", "in", today), orderBy("start", "asc")

I'd like a Firestore query, so that I can fetch all documents between 02/12/2022 - 00:00:00.000 && 03/12/2022 00:00:00.000, ordered by the Date property start, so that I can bucketsize my firestore data request and limit overreads, then use said documents to visually filter accordingly via the front-end.

Can you assist me with this?

CodePudding user response:

How to get start and end of day in Javascript?

const start = new Date();
start.setUTCHours(0,0,0,0);

const end = new Date();
end.setUTCHours(23,59,59,999);

Firestore query by date range

query(
  meetingsCollection,
  where("start", ">=", start),
  where("start", "<=", end)
  orderBy("start", "asc")
)

CodePudding user response:

  db.collection("collection_name")
  .where("start", ">=", "02/12/2022 00:00:00.000")
  .where("start", "<=", "03/12/2022 00:00:00.000")
  .orderBy("start")
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      // doc.data() contains the data for the document
    });
  });
  • Related