How to get real-time updates with Firebase Firestore using @capacitor-firebase/firestore? #758
-
Problem Description: I am using FirebaseFirestore in the following way in my application: import { FirebaseFirestore } from '@capacitor-firebase/firestore';
getAllFromSubcollection(
subcollectionName: string,
): Promise<GetCollectionGroupResult<I_SubscriptionOld>> {
return FirebaseFirestore.getCollection({
reference: `${this.userDocRef}/${subcollectionName}`,
});
} And I consume it like this in a component: async getSubsListValue() {
this.stateService.isShowLoadingSubsSignal.set(true);
try {
this.subsChanges$ = await this.firebaseCrudService.getAllFromSubcollection(
'itemSubscription',
);
console.log('this.subsChanges$?.snapshots', this.subsChanges$.snapshots);
this.processSubscriptions(this.subsChanges$?.snapshots);
} catch (error) {
alert('Error al obtener suscripciones: ' + JSON.stringify(error));
} finally {
this.stateService.isShowLoadingSubsSignal.set(false);
}
} The problem: Could anyone help me with an example or recommendation to achieve this using @capacitor-firebase/firestore? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for your request. You just need to add a snapshot listener using one of the following methods:
Here is an example from the Usage section: const addDocumentSnapshotListener = async () => {
const callbackId = await FirebaseFirestore.addDocumentSnapshotListener(
{
reference: 'users/Aorq09lkt1ynbR7xhTUx',
},
(event, error) => {
if (error) {
console.error(error);
} else {
console.log(event);
}
}
);
return callbackId;
}; |
Beta Was this translation helpful? Give feedback.
Thank you for your request. You just need to add a snapshot listener using one of the following methods:
Here is an example from the Usage section: