My Firestore has a collection of Events which includes a Timestamp field, startDate. At the moment, there are 4 events: one today, two further in the future and one is dated 1 May 2020.
In my app, I only care about the Events that are not in the past. So, I've set up my query as follows:
let today = Date()
let todayMidnight = getMidnight(for: today)!
let todayTimeStamp = Timestamp(date: todayMidnight)
activitiesCollection
.order(by: "startDate")
.whereField("startDate", isGreaterThanOrEqualTo: todayTimeStamp)
activitiesCollection.addSnapshotListener { (snapshot, error) in
I've tried with and without the order(by:) clause.
After initially using todayTimeStamp in my query, I also tried specifying my date parameter as today and todayMidnight as per Frank's answer to this post.
That makes six variations (with/without sorting, three date constants), and in all cases, the query is returning every document in the collection, as if it's ignoring the query altogether.
What am I doing wrong? How can I return only the documents I want instead of all of them?