AngularFirestore - Date filtering


#1

Hi!

I’m using the AngularFirestore to get data from a firebase database into my ionic application. In the collection I have a field (called “Start”) with a timestamp, and want to filter out documents where the timestamp is in the future.

I tried to use the lambda expression below, but my IDE tells me that “Property ‘Start’ does not exist on type ‘Items[]’”. Does anyone know how to solve the problem?

  public itemsCollection: AngularFirestoreCollection<Items>;
  public items: Observable<Items[]>;

  constructor(public afd: AngularFirestore) {
    
    this.itemsCollection = this.afd.collection('itemCollection'); 
    this.items = this.itemsCollection.valueChanges();

    var currentDate = new Date().getTime();
    this.itemsCollection.valueChanges()
      .filter ((data) => new Date(data.Start).getTime() < currentDate)
      .subscribe ((data2) => console.log(data2));    
  }

I also tried to use an interface, but if doesn’t make any difference.

interface Items {
 ....
 ....
 Start;
 ....
 ....
}

#2

Hey, sorry but this is really bad written. We have here: items, Items, Items[], Observable<Items[]>, itemsCollection, AngularFirestoreCollection

Please remove not necessary code e.g. ‘items’ are not used, only assignment. and rename this variables :slight_smile: Then you will see and error.


#3

Hi!

Thank you! As you can see, I am new to both Firebase and Angular, and have I hard time finding good resources online.

I don’t find the error, even after renaming the variables.