useCollection usingwithConverter
and toFirestore
not called after addDoc
#1437
-
Let's say I have this converter: const dateConverter = {
toFirestore(entry: Entry): DocumentData {
return {
...entry,
date: $moment(entry.date, 'YYYY-MM-DD').toDate(),
};
},
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): DocumentData {
const data = snapshot.data(options)!;
return { ...data, date: $moment(data.date.toDate()).format('YYYY-MM-DD') };
},
}; And I bind it to my query like so: const entries = useCollection<Entry>(
query(
collection(db, 'entries').withConverter(dateConverter),
where('user', '==', user.value?.uid),
where('date', '>', $moment(selectedDay.value).startOf('week').toDate()),
where('date', '<', $moment(selectedDay.value).endOf('week').toDate()),
),
{
ssrKey: 'entries',
},
); The async function addEntry(entry: Entry) {
await addDoc(collection(db, 'entries'), {
...entry,
user: user.value?.uid,
project: doc(db, 'projects', entry.project.id)
});
} |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Oct 6, 2023
Replies: 1 comment 1 reply
-
That's because you are passing just the collection without the converter to addDoc(collection(db, 'entries').withConverter(...), newDoc) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mrleblanc101
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's because you are passing just the collection without the converter to
addDoc()
. You need to pass it there too: