toFirestore
inside globalFirestoreOptions.converter
is never called
#1499
-
Reproduction. Steps to reproduce the bugI created this global converter, the fromFirestore gets called, but not the toFirestore. globalFirestoreOptions.converter = {
toFirestore(docData: any) {
console.log('test 1');
return {
created_at: serverTimestamp(),
...docData,
}
},
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): DocumentData {
console.log('test 2');
const data = firestoreDefaultConverter.fromFirestore(snapshot)!;
return data;
},
}; Expected behaviorBoth toFirestore and fromFirestore should be called. Actual behaviorOnly the fromFirestore is called. Additional informationI want to automatically add a
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
It works if I use const addDefaultFields = {
toFirestore(docData: DocumentData): DocumentData {
console.log('test 1');
return {
created_at: serverTimestamp(),
...docData,
}
},
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): DocumentData {
console.log('test 2');
const data = firestoreDefaultConverter.fromFirestore(snapshot)!;
return data;
},
};
...
async function addProject(option: Project) {
const project = await addDoc(collection(db, 'projects').withConverter(addDefaultFields), {
name: option.name,
user: user.value!.uid,
})
return { id: project.id, name: option.name };
} |
Beta Was this translation helpful? Give feedback.
It works if I use
.withConverter
instead.Exemple: