Home > Net >  Firestore special query (with arrays)
Firestore special query (with arrays)

Time:10-06

Hey guys I'm having a problem with one of my queries!

I have some "store" docs, and in those docs I got an array of "products".

Each product has a "expirationDate". I would like to know how could I get the "store"'s where there is at least 1 expired "product". Something like:

const currentDate = new Date();
  db.collection("stores")
  .where("for each (product) {return product.expirationDate}", "<", currentDate.getTime())
  .get().then((querySnapshot) => {
    // Get all stores with at least 1 expired product
  });

CodePudding user response:

Firestore can only order/filter on values that are stored in the documents that it returns. If you want to filter on the number of expired products, you will have to store that value in a field in the document - and keep it up to date (for example in a daily process).

  • Related