错误:将循环结构转换为 JSON -->从具有构造函数"拓扑"的对象开始 |属性 's' -> 对象与 ....在 Nodejs Express 中



这是我的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)})

模型:

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: Schema.Types.ObjectId,
ref: 'Review'
}
]}, opts);

这是来自查询的ejs:

<form action="/results/?" class="d-flex mb-5">
<input class="form-control me-2" type="search" placeholder="Search Your Campgrounds ...." name="search_query" aria-label="Search">
<button class="btn btn-outline-dark" type="submit">Search</button>
</form>

上面的问题解决了,我忘了在Campground.find()中写入await,因为它是从数据库中提取数据的异步过程