admin管理员组文章数量:1335361
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');
本文标签:
版权声明:本文标题:javascript - Mongoose, getting TypeError: Cannot read properties of undefined (reading 'find') - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742356524a2459523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论