node.js - 尝试 findAll() 时集合返回空。RESTful 和 Mongodb
问题描述
我正在尝试使用 REST、NodeJS、ExpressJS 和 MongoDB 地图集实现 RESTful API。我已成功连接我的地图集数据库,我正在尝试从“个人信息”集合中检索所有内容。
我的图集云集合如下所示:
_id:ObjectId("60884283fd31d723047c6f7c")
customerID:"6543524356"
Title:"Ms"
Fname:"Anna"
Lname:"Dunne"
mobile:"0764323456"
email:"anna@here.ie"
我的 server.js 成功连接到我的云数据库
我的 model.js 看起来像这样:
const mongoose = require('mongoose');
// create a mongoose schema for a quotation
const PersonalInfoSchema = mongoose.Schema({
customerID: String,
Title: String,
Fname: String,
Lname: String,
mobile: String,
email: String
}, {
timestamps: true
});
// export the model to our app
module.exports = mongoose.model('Personal_information', PersonalInfoSchema);
这是我的 controller.js 的一部分,假设可以在我的个人信息中找到所有文档
exports.findAll = (req, res) => {
Personal_information.find()
.then(personal_information => {
res.send(personal_information);
}).catch(err => {
res.status(500).send({
message: err.message || "An error occurred while retrieving all personal information."
});
});
};
我已将路线定义为
module.exports = (app) => {
app.get('/personal_information', personal_information.findAll);
}
但是当我在邮递员中运行 url 时,它返回空,即使我的个人信息集合中有 3 个文档。任何想法为什么以及如何解决它?
解决方案
推荐阅读
- c - 找不到 config.h 文件(ssh 源代码)
- typescript - 在打字稿中省略不需要的同名接口方法
- geoviews - GeoViews:具有 matplotlib 后端的 GeoDataFrames 的分类图例
- pine-script - 找出有多少短信号和长信号
- javascript - 扩展事件是否有下拉菜单?
- java - 为什么受保护的构造函数可以用于包外的新实例?
- python - 使用 Python 从 Twitter 流 API 中提取特定的 JSON 字段
- php - PHP获取数组中每n个元素的总数
- c++ - 复制构造函数已删除错误。编译器没有调用移动赋值运算符
- html - 如果选中,则更改切换背景