Node.js TypeError:POINT.find不是mongoose函数
在为mongoose执行Model.find()时遇到此错误,每个声明看起来都不错。 mongo Atlas中的数据库是Node.js TypeError:POINT.find不是mongoose函数,node.js,mongodb,express,mongoose,typeerror,Node.js,Mongodb,Express,Mongoose,Typeerror,在为mongoose执行Model.find()时遇到此错误,每个声明看起来都不错。 mongo Atlas中的数据库是点 经验 /模型 point.model.js /路线 api.js server.js point.model.js TypeError: Point.find is not a function at /Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/routes/api.j
点
- 经验
- /模型
point.model.js
- /路线
api.js
server.js
- /模型
TypeError: Point.find is not a function
at /Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/routes/api.js:10:11
at Layer.handle [as handle_request] (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/layer.js:95:5)
at /Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:335:12)
at next (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:174:3)
at router (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:47:12)
at Layer.handle [as handle_request] (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:317:13)
at /Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:335:12)
at next (/Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:275:10)
at /Users/milan/MILAN/react-hand-maridian/react-hand-meridian/exp/node_modules/express/lib/router/index.js:635:15
API.js
const mongoose = require("mongoose");
const pointSchema = new mongoose.Schema({
name: {
type: String,
unique: true,
required: true,
},
meridianGroup: {
type: String,
required: true,
},
sideFacing: {
type: String,
required: true,
},
rightHand: {
type: Object,
offX: {
type: Number,
required: true,
},
offY: {
type: Number,
required: true,
},
},
leftHand: {
type: Object,
offX: {
type: Number,
required: true,
},
offY: {
type: Number,
required: true,
},
},
});
module.export = mongoose.model("point", pointSchema);
以错误的方式导出模型
const router = require("express").Router();
const Point = require("../models/point.model");
// This are are API routes
// Get all points
router.route('/points').get((req, res)=>{
console.log(Point)
// res.send("all points")
Point.find()
.then(points => res.json(points))
.catch(err => res.status(400).json(err))
});
module.exports = router;
相反,如果
module.exports = mongoose.model("point", pointSchema);
以错误的方式导出模型
const router = require("express").Router();
const Point = require("../models/point.model");
// This are are API routes
// Get all points
router.route('/points').get((req, res)=>{
console.log(Point)
// res.send("all points")
Point.find()
.then(points => res.json(points))
.catch(err => res.status(400).json(err))
});
module.exports = router;
相反,如果
module.exports = mongoose.model("point", pointSchema);
您可能正在导入
点
错误,console.log(点)的输出是什么?输出为空{}您没有正确导入点您可能正在导入点
错误,console.log(点)的输出是什么?输出为空{}您没有正确导入点