简体   繁体   中英

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: 在此处输入图像描述

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));
  }
 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM