【发布时间】:2020-03-10 08:27:20
【问题描述】:
我正在尝试从 MongoDB 数据库中获取所有用户。但是由于某种原因,最近该请求没有获取任何内容。
这是我尝试获取数据的代码:
app.get('/api/allusers', (req, res) => {
Employee.find()
.then(rettrievedData => {
res.json(rettrievedData)
});
});
这是猫鼬模型:
const mongoose = require('mongoose');
const employeeSchema = mongoose.Schema({
name: { type: String },
surName: { type: String },
mail: { type: String },
phone: { type: String },
});
module.exports = mongoose.model('Employee', employeeSchema, 'employee.employees');
这是连接Mongo的代码
mongoose.connect("mongodb+srv://Kiril:xxxxxxxxxxxxx@cluster0-owdfy.mongodb.net/employee?retryWrites=true&w=majority")
.then(() => {
console.log("Connected")
})
我还检查了数据库中是否有数据,但由于某种原因,Employee.find() 没有检索到任何内容。可能是什么原因?
提前致谢。
【问题讨论】: