gpt4 book ai didi

node.js - Nodejs Express 中的错误 : Converting circular structure to JSON --> starting at object with constructor 'Topology' | property 's' -> object with . ...

转载 作者:行者123 更新时间:2023-12-03 08:15:53 32 4
gpt4 key购买 nike

这是我的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,因为它是从数据库中提取数据的异步过程

关于node.js - Nodejs Express 中的错误 : Converting circular structure to JSON --> starting at object with constructor 'Topology' | property 's' -> object with . ...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69431095/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com