Reactjs 为什么使用无效数据调用此错误函数Query.where()。不支持的字段值:firebase中是否发生未定义的事件?
我正试图从firestore数据库中获取特定的文档。所以我匹配了文档中的Reactjs 为什么使用无效数据调用此错误函数Query.where()。不支持的字段值:firebase中是否发生未定义的事件?,reactjs,firebase,google-cloud-firestore,next.js,Reactjs,Firebase,Google Cloud Firestore,Next.js,我正试图从firestore数据库中获取特定的文档。所以我匹配了文档中的slug字段。但这给我带来了一个错误 使用无效数据调用函数Query.where()。不支持的字段值:未定义 我的语法是这样的 export async function getStaticProps(context) { const { slug } = context.params; const res = await firebase .firestore() .collection(&quo
slug
字段。但这给我带来了一个错误
使用无效数据调用函数Query.where()。不支持的字段值:未定义
我的语法是这样的
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: {},
};
}
}
我的firestore文档看起来像
顺便说一句,我使用的是Next.Js的SSG。这是因为在getStaticPaths
中,slug
没有返回。
您必须在参数中返回相同的名称(这里是slug)才能进入URL参数(context.params)
第二个slug参数中的引号<代码>其中(“slug”,“slug=”,“slug”)?看,我所做的是从URL参数中调出slug值<代码>常量{slug}=context.params代码>。我不能在其中加上双引号。我相信它在抱怨
slug
变量未定义。您的getstaticpath
是否返回了所有正确的、可能的路径?如果slug
未定义,可能值得提前返回。
params: { slug: book.data().slug }