简体   繁体   中英

Error: Converting circular structure to JSON --> starting at object with constructor 'Topology' | property 's' -> object with .... in Nodejs Express

This my index.js. Where i am trying for search functionality through query string. I am getting query from client but the error is occuring in campground.find(), its giving above error

app.get('/results', (req, res) =>{
const {search_query} = req.query
console.log(search_query);
const campgrounds = Campground.find({title: 'gizzly Camp'})
res.send(campgrounds)})

Model:

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);

This is ejs from where query is coming:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM