Error: Converting circular structure to JSON --> starting at object with constructor 'Topology' | property 's' -> object with .... in Nodejs Express
Error: Converting circular structure to JSON --> starting at object with constructor 'Topology' | property 's' -> object with .... in 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()中写等待,因为它是从数据库中提取数据的异步过程
这是我的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()中写等待,因为它是从数据库中提取数据的异步过程