Reputation: 423
I'm trying to get a specific doc from my firestore database. So I matched the slug
field in the doc. But it throws me an error...
Function Query.where() called with invalid data. Unsupported field value: undefined
My syntax looks like this
export async function getStaticProps(context) {
const { slug } = context.params;
const res = await firebase
.firestore()
.collection("books")
.where("slug", "==", slug)
.get();
const book = res.docs.map((book) => book.data());
if (book.length) {
return {
props: {
book: book[0],
},
};
} else {
return {
props: {},
};
}
}
and my firestore document looks like
BTW I'm using Next.Js's SSG.
Upvotes: 2
Views: 6305
Reputation: 1
Check the page before getStaticProps to see if it's actually receiving the data. I had this same issue, and the error was the previous page wasn't passing the data
Upvotes: 0
Reputation: 423
It is because in the getStaticPaths slug
is not returned.
You've to return the same name(here slug) in params to get in the URL params(context.params).
params: { slug: book.data().slug }
Upvotes: 1