You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example does not work at all. The thrown error is TypeError: collection(db,'posts').withConverter(postConverter).doc is not a function. (In 'collection(db,'posts').withConverter(postConverter).doc()', 'collection(db,'posts').withConverter(postConverter).doc' is undefined.
The example is probably from the v8 version of the library. Can someone provide the v9 version of the example here until the docs get patched?
Steps and code to reproduce issue
class Post {
constructor(title, author) { }
toString() {
return this.title + ', by ' + this.author;
}
}
const postConverter = {
toFirestore(post) {
return { title: post.title, author: post.author };
},
fromFirestore(
snapshot,
options
) {
const data = snapshot.data(options);
return new Post(data.title, data.author);
}
};
const db = getFirestore();
const postSnap = await collection(db,'posts').withConverter(postConverter).doc().get();
const post = postSnap.data();
if (post !== undefined) {
post.title; // string
post.toString(); // Should be defined
post.someNonExistentProperty; // TS error
}
The text was updated successfully, but these errors were encountered:
@marcusx2 Thank you for pointing out this obvious issue with the documentation. I have opened a PR that re-writes the sample code. If you have some time, please take a look and let me know what you think. I added a "simple" converter and a "complex" converter sample: #7673
Operating System
macOS
Browser Version
Safari 16.5.2
Firebase SDK Version
10.4.0
Firebase SDK Product:
Firestore
Describe your project's tooling
index.html with source tag. Just javascript.
Describe the problem
This example does not work at all. The thrown error is
TypeError: collection(db,'posts').withConverter(postConverter).doc is not a function. (In 'collection(db,'posts').withConverter(postConverter).doc()', 'collection(db,'posts').withConverter(postConverter).doc' is undefined
.The example is probably from the v8 version of the library. Can someone provide the v9 version of the example here until the docs get patched?
Steps and code to reproduce issue
The text was updated successfully, but these errors were encountered: