I am trying to implement a RESTful API using REST, NodeJS, ExpressJS and MongoDB atlas. I have sucessfully connected my atlas database and I am trying to retrieve everything from the collection "personal_information".
My atlas cloud collection looks like this:
_id:ObjectId("60884283fd31d723047c6f7c")
customerID:"6543524356"
Title:"Ms"
Fname:"Anna"
Lname:"Dunne"
mobile:"0764323456"
email:"anna@here.ie"
My server.js connects successfully to my cloud database
My model.js looks like this:
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);
here is the portion of my controller.js that is suppose to find all documents in my personal_information
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."
});
});
};
I have defined the route as
module.exports = (app) => {
app.get('/personal_information', personal_information.findAll);
}
but when I run the url in postman, it returns empty, even though I have 3 documents in my personal_information collection. Any ideas why and how to fix it?