Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
Firestore real time data update by limit on the last added documents

I have a firestore database where it gets new documents every second from another gcp service, I'm using that data to plot a line chart in front end angular12 app. the problem I have is the front end is getting the whole database documents which it fills the chart with over 1000 data, I tried to use ref.limit but then I don't get the latest document and the chart keeps showing the same 10 objects. has anyone faced the same problem and what would be the best approach?

in service.ts

export class ChartsService {
  
    private itemsCollection: AngularFirestoreCollection<Item>;
    items: Observable<Item[]>;  

    constructor(private afs: AngularFirestore) {
      this.itemsCollection = afs.collection<Item>('DCI2');
      this.items = this.itemsCollection.valueChanges();
    } 

componant.ts

ngOnInit(): void {

    this.ChartsService.getDocs().subscribe((data) => {
          this.items$ = data;
         
          if (this.items$) {
            this.items$.forEach((element) => {
              this.timestamp.push(element.timestamp);
              this.temp1.push(element.temp1); 
              this.temp2.push(element.temp2)      
            });

            console.log(this.temp1);
 
          }
        });
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since you seem to have a timestamp in your documents, you can order by descending date and then limit:

this.itemsCollection = afs.collection<Item>('DCI2', ref => ref.orderBy("timestamp", desc).limit(10));
this.items = this.itemsCollection.valueChanges();

Also see the AngularFire documentation on querying collections.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda