const express=require("express");
const { stringify } = require("querystring");
const router= express.Router()
const Db=require("../models/Db")
router.get("/",(req,res)=>{
res.render("index.hbs");
})
.post("/addData",async(req,res)=>{
const data=req.body
console.log(data);
try{
const todo= new Db({
title:req.body.title,
query:req.body.query,
})
const result= await Db.create(todo)
console.log("data saved")
console.log(todo.title)
console.log(todo.query)
}catch(err){
console.log(err);
}
res.redirect("/")
})
//这显示尝试保存数据时,操作todos.insertOne()
缓冲在10000 ms后超时//请在此处帮助我
const express=require("express");
const { stringify } = require("querystring");
const router= express.Router()
const Db=require("../models/Db")
router.get("/",(req,res)=>{
res.render("index.hbs");
})
.post("/addData",async(req,res)=>{
const data=req.body
console.log(data);
try{
const todo= new Db({
title:req.body.title,
query:req.body.query,
})
const result= await todo.save
console.log("data saved")
console.log(todo.title)
console.log(todo.query)
}catch(err){
console.log(err);
}
res.redirect("/")
})
module.exports=router
//这里我没有得到错误,但数据没有添加到数据库请帮助我这里///这里它没有显示任何错误,但没有数据得到保存时,我检查mongodb指南针
1条答案
按热度按时间idfiyjo81#
谢谢我解决了超时错误从const数据库的URL=“mongodb://localhost:27017/myNewDb”到const数据库的URL=“mongodb:0.0.0.0:27017/myNewDb“