const express = require('express');
const cors = require('cors');
const mongoose = require('mongoose');
const app = express()
app.use(express.json())
app.use(express.urlencoded())
app.use(cors())
const dotenv = require('dotenv');
dotenv.config()
mongoose.connect(process.env.DB_ACCESS, () => {
console.log("db connected successfully..")
})
const hospitalTemplate = new mongoose.Schema({
state: {
type: String,
required: true
},
city: {
type: String,
required: true
},
hospitalname: {
type: String,
required: true
},
mobilenumber: {
type: Number,
required: true
},
image1url: {
type: String,
required: true
},
rating: {
type: Number,
required: true
},
availablebeds: {
type: Number,
required: true
}
})
const Hospital = new mongoose.model('Hospital', hospitalTemplate)
// // Routes
app.get("/search", async (req, res)=> {
await Hospital.find({}, (err, data)=> {
if (data) {
res.send(data);
console.log(data)
} else {
res.send({ message: "data problem" });
console.log("data problem");
}
}).clone().catch(function(err){ console.log(err)})
})
app.listen(4000,() => {
console.log("server is running")
})
Can someone help me with this problem, mongoose not fetching any data from MongoDB atlas? Everything is fine and I am able to fetch data from cmd, but with mongoose, it returns an empty array.