[英]TypeError: Cannot read properties of undefined (reading 'find')
我收到錯誤“TypeError: Cannot read properties of undefined (reading 'find')”,它指向代碼塊:
app.get('/Organizations', (req,res) => {
Organizations.find({}).then((organization) => {
res.send(organization);
}); })
app.js,導入 mongoose 架構:
const {Organizations} = require('./db/models');
組織.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
}
您在導出Organisations
時添加了括號而不是括號。 試試這個:
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}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.