Firebase Firestore Query Between Two Timestamps

后端 未结 3 1132
温柔的废话
温柔的废话 2021-01-16 12:16

I want to find events that are a on now and upcoming (next 30 days) but that are also not in the past.

When i run this as a cloud function, I get \"Cannot have inequ

3条回答
  •  无人及你
    2021-01-16 12:36

    Since you have two fields to check with ranges, I'm not sure this is doable with a single query. What you can do instead is perform two queries, merge the results on the client, and perform a final filter to get the exact matches.

    1. Make an assumption about the maximum duration for an event. Call that amount of time "X".
    2. Query for all documents where startDate is greater than now - X, and also less than now + 30 days. Call this result set "A".
    3. Query for all documents where endDate is greater than now, and also less than now + 30 days. Call this result set "B".
    4. On the client, iterate all the results from A and B, checking to see if the start and end dates fit the criteria you want.

    I can't think of a way to structure your data that will do this with a single query.

提交回复
热议问题