'ModelFindById return undefined
I run this code and variable company returns me undefined .I put on the parenthesis one example of my id from collection and it is works. Is it a model name issue? or is it the code issue and I need to rewrite it again?
const getCompanyProfile = asyncHandler(async (req, res) => {
const company = await Company.findById(req.company._id)
if(company) {
res.json({
_id: company._id,
name: company.name,
email: company.email,
phone: company.phone,
})
} else {
res.status(404)
throw new Error('Company not found')
}
})
import mongoose from "mongoose"
const companySchema = mongoose.Schema({
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
phone: {
type: String,
required: true
},
password: {
type: String,
required: true
},
mechanic: {
type: Boolean,
},
electric: {
type: Boolean,
},
painted: {
type: Boolean,
},
tunning: {
type: Boolean,
},
itp: {
type: Boolean,
},
tow: {
type: Boolean,
}
}, { timestamps: true })
const Company = mongoose.model('Company', companySchema)
export default Company
I expect to resolve this problem, but it is too hard
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
