【发布时间】:2020-08-08 18:16:04
【问题描述】:
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
在为 mongoose 执行 Model.find() 时遇到此错误,每个声明看起来都不错。
mongo Atlas中的数据库是point
- Exp
- /型号
point.model.js
- /路线
api.js
server.js
- /型号
point.model.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);
API.js
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;
【问题讨论】:
-
您可能导入了
Point错误,console.log(Point) 的输出是什么? -
输出为空{ }
-
您没有正确导入 Point
标签: node.js mongodb express mongoose typeerror