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

131
Views
Google firestore para obtener un registro único. pero no es capaz de lanzar al objeto

Esta es mi clase de controlador. donde quiero convertir datos a mi objeto personalizado

 getRegister(node:string) { this.db.firestore.collection('databasetable') .where('profileId','==', node) .get() .then(querySnapshot => { querySnapshot.forEach(function (doc) { console.log(doc.id); // id of doc console.log(doc.data()); // data of doc //Want to cast my object here for displaying into UI }) }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El método data() siempre devuelve un objeto JSON. Creo que está buscando los métodos withConverter (relativamente recientes) y la clase FirestoreDataConverter :

 await firebase.firestore() .collection('posts') .withConverter(postConverter) // 👈 this is a custom class that performs the conversion .doc().get();

El postConverter anterior es un objeto que tiene los métodos toFirestore y fromFirestore para convertir el JSON de/a la clase personalizada, por ejemplo:

 const postConverter = { toFirestore(post: Post): firebase.firestore.DocumentData { return {title: post.title, author: post.author}; }, fromFirestore( snapshot: firebase.firestore.QueryDocumentSnapshot, options: firebase.firestore.SnapshotOptions ): Post { const data = snapshot.data(options)!; return new Post(data.title, data.author); } };

Consulte también la documentación del método DocumentReference.withConverter y la clase FirestoreDataConverter , de donde obtuve los ejemplos de código anteriores.

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!