I'm getting the error, TypeError: Cannot read properties of undefined (reading 'find')
which points to the block of code:
app.get('/Organizations', (req,res) => {
Organizations.find({}).then((organization) => {
res.send(organization);
}); })
app.js, importing mongoose schema:
const {Organizations} = require('./db/models');
Organization.model.js:
const mongoose = require('mongoose');
const OrganizationsSchema = new mongoose.Schema({
organizationName:{
type: String,
required: true,
minlength:1,
trim: true
}
})
const Organizations = mongoose.model( 'Organizations', OrganizationsSchema);
module.exports = (Organizations)
index.js:
const { Organizations } = require('./Organizations.model');
module.exports = {
Organizations
}
I'm getting the error, TypeError: Cannot read properties of undefined (reading 'find')
which points to the block of code:
app.get('/Organizations', (req,res) => {
Organizations.find({}).then((organization) => {
res.send(organization);
}); })
app.js, importing mongoose schema:
const {Organizations} = require('./db/models');
Organization.model.js:
const mongoose = require('mongoose');
const OrganizationsSchema = new mongoose.Schema({
organizationName:{
type: String,
required: true,
minlength:1,
trim: true
}
})
const Organizations = mongoose.model( 'Organizations', OrganizationsSchema);
module.exports = (Organizations)
index.js:
const { Organizations } = require('./Organizations.model');
module.exports = {
Organizations
}
Share
Improve this question
edited Mar 31, 2022 at 13:56
Youssouf Oumar
46.4k16 gold badges102 silver badges105 bronze badges
asked Dec 28, 2021 at 9:46
DillonDillon
1542 gold badges6 silver badges15 bronze badges
0
1 Answer
Reset to default 4It's an import/export problem. In Organization.model.js
you used parentheses instead of curly braces when exporting Organisations
. Export it like so:
module.exports = {Organizations}
And import it this way:
const { Organizations } = require('./Organizations.model');
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742356524a4428546.html
评论列表(0条)