您好,我是 Next.js 的新手,我知道在 getStaticProps 中 Next.js 将在构建时预渲染此页面,在 getServerSideProps 中 Next.js 将使用 getServerSideProps 返回的数据在每个请求上预渲染此页面
但我想要一个何时对网站使用 getStaticProps 和 getServerSideProps 的示例
这是我的index.js。我正在尝试通过查询字符串进行搜索功能。我收到来自客户端的查询,但错误发生在 Campground.find() 中,它给出了上述错误
app.get('/results', (req, res) =>{
const {search_query} = req.query
console.log(search_query);
const campgrounds = Campground.find({title: 'gizzly Camp'})
res.send(campgrounds)})
Run Code Online (Sandbox Code Playgroud)
模型:
const ImageSchema = Schema({
url:String,
filename: String,})
const CampgroundSchema = Schema({
title: String,
image: [
ImageSchema
],
price: Number,
description: String,
category: {
type: Schema.Types.ObjectId,
ref: 'Category',
},
location: String,
geometry: {
type: {
type: String,
enum: ['Point'],
required: true
},
coordinates: {
type: [Number],
required: true,
}
},
author:
{
type: Schema.Types.ObjectId,
ref: 'User'
},
reviews: [
{
type: …
Run Code Online (Sandbox Code Playgroud)