【发布时间】:2021-12-09 16:54:38
【问题描述】:
我使用了 Vercel 文档中提供的示例,每 15 秒后从 MongoDB 获取数据,但不幸的是该功能不起作用。我应该怎么做才能使其按预期工作?
export async function getStaticProps() {
const allData = getSortedData();
const client = await clientPromise;
const isConnected = await client.isConnected();
const alerts = await client.db()
.collection("alerts")
.find({})
.limit(6)
.toArray();
const alertsData = JSON.parse(JSON.stringify(alerts));
return {
props: {
allData,
isConnected,
alertsData
},
revalidate: 15,
};
}
【问题讨论】:
-
请记住,重新验证不会在 15 秒后自动发生。对该页面的请求需要触发服务器上的重新验证。请参阅此相关问题:How does the revalidate process in Incremental Static Regeneration work?。
标签: reactjs mongodb next.js vercel getstaticprops