Thu Aug 10 2023
Fetch MongoDB Data
Node JS232 views
File Name: user-model.js
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
fstName: String,
lstName: String,
email: String
});
const User = mongoose.model('User', userSchema);
module.exports = User;
File Name: user-controller.js
const User = require('./user.model');
const getUserList = async () => {
try {
const users = await User.find();
console.log('User List: ', users);
} catch(e) {
throw new Error(e);
}
}
module.exports = {getUserList}
Author:Geekboots