Reputation: 154
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
}
Upvotes: 2
Views: 11945
Reputation: 46261
It'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');
Upvotes: 3