Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

84
Views
Actualización de datos en tiempo real de Firestore por límite en los últimos documentos agregados

Tengo una base de datos de firestore donde obtiene nuevos documentos cada segundo de otro servicio de gcp, estoy usando esos datos para trazar un gráfico de líneas en la aplicación front-end angular12. el problema que tengo es que el front-end está obteniendo todos los documentos de la base de datos que llena el gráfico con más de 1000 datos, traté de usar ref.limit pero luego no obtengo el documento más reciente y el gráfico sigue mostrando los mismos 10 objetos . ¿Alguien ha enfrentado el mismo problema y cuál sería el mejor enfoque?

en servicio.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(); }

componente.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 answers
Answer question

0

Dado que parece tener una marca de tiempo en sus documentos, puede ordenar por fecha descendente y luego limitar:

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

Consulte también la documentación de AngularFire sobre consultas de colecciones .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!