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>
The Above Question is solved I forgot to write await in Campground.find() since it is asynchronous process of extracting the data from database