0

I have a meeting collections with documents like:

{
name: John
date: 1 Jan 2021
time: 10am
meeting note: morning standup
}

I want to get documents with say name=John, and dates after today.

Since Firestore does not support query using two fields, I suppose I need to get name=John and filter myself for dates after today? If yes, is there a more efficient and effective way to do that?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
william007
  • 17,375
  • 25
  • 118
  • 194
  • 1
    Why would you say it doesn't support queries using two fields? As long as you create the corresponding [index](https://stackoverflow.com/questions/50305328/firestore-whereequalto-orderby-and-limit1-not-working), it indeed does, right? – Alex Mamo Nov 30 '21 at 14:39

1 Answers1

1

While there are limits on the types of queries that Firestore can perform, this one seems well within its limits. In JavaScript it'd be:

import { query, where } from "firebase/firestore";  

const q1 = query(citiesRef, where("nam", "==", "John"), where("date", ">=", new Date()));

If the query doesn't immediately return results, check the log output as you may need to create a compound index on the two fields. The log output in that case will contain an error message with a direct link to create the index (with the fields already filled in).

Also see the documentation on compound queries.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807