[英]TypeError: circular structure to JSON starting at object with constructor 'ClientRequest' property 'socket' -> object with constructor 'Socket'
[英]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() 中写 await 因为它是从数据库中提取数据的异步过程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.