I am attempting to establish a connection with my mongodb database and retrieve some data within the server side component of my nextJs application
Below is my connection function:
import mongoose from "mongoose"
const connectDb = async()=>{
try {
await mongoose.connect(process.env.MONGO_DB)
console.log("Connected Successfully")
} catch (error) {
console.log(error)
}
}
export default connectDb
Here is my model:
import { Schema, model, models } from "mongoose";
interface IProject {
id: number,
name: string,
skills: string[],
demoLink: string,
repoLink: string,
imgUrl:string,
}
const projectSchema = new Schema<IProject>({
id: {type:Number},
name: {type:String,required:[true,"DemoLink is Required"]},
skills: {type:[],required:[true,"Enter One Skill at least"]},
demoLink: {type:String, required:[true,"DemoLink is Required"]},
repoLink: {type:String, required:[true,"RepoLink is Required"]},
imgUrl:{type:String, required:[true,"Image Url is Required"]},
})
const Project = models.Project || model<IProject>("Project", projectSchema)
export default Project
Finally, this is my server component:
import Project from "@/models/project"
import connectDb from "../connect"
const Home = async () => {
await connectDb()
const project = await Project.find()
return (
<div>{project && JSON.stringify(project)}</div>
)
}
export default Home
After running my application, I encountered the following error message: "MongooseError: Operation projects.find()
buffering timed out after 10000ms at Timeout"