Model.find({params }) Mongoose and Node js

I am trying to get all people with a specific name from the database and it keeps return null.
Here’s my schema
const mongoose = require(‘mongoose’)
let bookSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
author: {
type: String,
required: true
},
page: {
type: Number
},
edition: {
type: String
},
dateCreated: {
type: Date,
default: Date.now
}
})
let Book = mongoose.model(‘Book’,bookSchema)

and here’s the code
router.get(’/:author’, async (req, res) =>{
const book = await Book.find({author: req.params.author}, (err,data)=>{
if (err) {console.log(err)}
else{
res.json(book)
}
})
})

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.