Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get the firestore data with a date range, boolean, and not equals?

I have these sessions and I wanted to retrieve the data of these users with:

session1 == true
session2 == false

and also get the data of those that did not choose meeting2 or selected !== meeting2:

This is the firestore document:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And how can I query it where DateEnd is greater than the date of today .

This is how I query it in firestore. So far, it isn’t working.

componentDidMount() {
    firestore
      .collection("users")
      .where("aptment.session2", "==", false)
      .where("aptment.selection", "!=", "meeting2")
       //DateEnd greater than today's date
      .get()
      .then((snapshot) => {
        const users = [];
        snapshot.forEach((doc) => {
          const data = doc.data();
          users.push({
            "User ID": doc.id, 
            Address: data.address,
          });
        });
        this.setState({ users: users });
      })
      .catch((error) => console.log(error));
  }
 

>Solution :

From the Firebase documentation on query limitations:

In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.

So you can’t have a >= condition on the DateEnd field when you already have a != condition on the aptment.selection field. You will have to do one of these condition in the query, and then perform the rest of the filtering in your application code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading