I’m currently creating a new API with MongoDB and Express, and I’m currently having this issue
“message”: “errorMongooseError: Operation userinfos.insertOne()
buffering timed out after 10000ms”
his is the way that I setup my API calls:
const express=require('express');
const router=express.Router();
const Userinfo=require("../Models/Userinfo")
router.get('/',(req,res)=>{
res.send("we are Post")
});
router.get('/Specic', async(req,res)=>{
try{
const data=await Userinfo.find();
console.log(data);
res.json(data)
}
catch(err)
{
res.json({message:err})
}
})
router.post("/",(req,res)=>{
const test= new Userinfo({
"Fname":req.body.Fname,
"Lname":req.body.Lname
});
console.log(test);
test.save().then(data=>{
res.json(data);
}).catch((err)=>{res.json({message:"error"+err})})
})
module.exports=router;
MoDel Defining like this Userinfo.js
const mongoose=require('mongoose');
/*const PoistSchema=mongoose.Schema({
Fname:String,
Lname:String,
DOB:Date.now()
});*/
const PostSchema=mongoose.Schema({
Fname:{
type:String,
require:true
},
Lname:{
type:String,
require:true
},
DOB:{
type:String,
default:Date.now
},
});
module.exports=mongoose.model("Userinfo",PostSchema)
App.js
const express=require('express');
const app=express();
const mongoose=require('mongoose');
require("dotenv/config");
const bodyParser=require("body-parser")
///Middlewares
//app.use(auth);
app.use(bodyParser.json());
const postroutes=require("./Routes/Posts");
app.use("/post",postroutes)
app.get('/',(req,res)=>{
res.send("we are om")
})
app.get('/posts',(req,res)=>{
res.send("we are Post")
})
try {
mongoose.connect(process.env.DBConnection,{useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex:true},()=>{
console.log("Sucess");
},(error)=>{
console.log(error);
});
console.log("ConnectedZZ")
} catch (error) {
console.log(error);
}
app.listen(3000);
Is there any suggestion to inset and get data.While getting data not getting any error.