Incorrect documentation
nguyenvukhang opened this issue · 1 comments
The city_custom_object.js file on master branch (link) is part of the Firestore Documentation examples.
// Firestore data converter
const cityConverter = {
toFirestore: (city) => {
return {
name: city.name,
state: city.state,
country: city.country
};
},
fromFirestore: (snapshot, options) => {
const data = snapshot.data(options);
return new City(data.name, data.state, data.country);
}
};It shows the fromFirestore method taking an options parameter.
However, the current implementation over at @google-cloud/firestore (link) shows that it's toFirestore that takes that parameter instead.
export interface FirestoreDataConverter<T> {
/**
* Called by the Firestore SDK to convert a custom model object of type T
* into a plain Javascript object (suitable for writing directly to the
* Firestore database). To use set() with `merge` and `mergeFields`,
* toFirestore() must be defined with `Partial<T>`.
*/
toFirestore(modelObject: T): DocumentData;
toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData;
/**
* Called by the Firestore SDK to convert Firestore data into an object of
* type T.
*/
fromFirestore(snapshot: QueryDocumentSnapshot): T;
}@nguyenvukhang Sorry for the delay here.
Note that the first snippet you added is using the Firebase JS SDK (see ref docs), which is different from the second snippet (that one uses @google-cloud/firestore, see their ref docs).
In the Firebase JS SDK (client side), fromFirestore does take an options parameter:
https://github.com/firebase/firebase-js-sdk/blob/480d7d560b6a3006d6dc8e141288177cb82f42bc/packages/firestore-types/index.d.ts#L52-L57