Jump to top

FirestoreDataConverter

interface

Converter used by withConverter() to transform user objects of type AppModelType into Firestore data of type DbModelType.

Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.

In this context, an "AppModel" is a class that is used in an application to package together related information and functionality. Such a class could, for example, have properties with complex, nested data types, properties used for memoization, properties of types not supported by Firestore (such as symbol and bigint), and helper functions that perform compound operations. Such classes are not suitable and/or possible to store into a Firestore database. Instead, instances of such classes need to be converted to "plain old JavaScript objects" (POJOs) with exclusively primitive properties, potentially nested inside other POJOs or arrays of POJOs. In this context, this type is referred to as the "DbModel" and would be an object suitable for persisting into Firestore. For convenience, applications can implement FirestoreDataConverter and register the converter with Firestore objects, such as DocumentReference or Query, to automatically convert AppModel to DbModel when storing into Firestore, and convert DbModel to AppModel when retrieving from Firestore.

Methods

fromFirestore

</>

Called by the Firestore SDK to convert Firestore data into an object of type AppModelType. You can access your data by calling: snapshot.data().

fromFirestore(snapshot: QueryDocumentSnapshot): ;

toFirestore

</>
Signature 1
</>

Converts a custom model object of type AppModelType into a plain Javascript object (suitable for writing directly to the Firestore database) of type DbModelType.

toFirestore(modelObject: WithFieldValue<>): WithFieldValue<>;
Signature 2
</>

Converts a custom model object of type AppModelType into a plain Javascript object (suitable for writing directly to the Firestore database) of type DbModelType.

toFirestore(modelObject: PartialWithFieldValue<>, options: SetOptions): PartialWithFieldValue<>;