MongoClient.connect(
"mongodb+srv://아이디:비번@cluster0.8cwcv.mongodb.net/db이름?retryWrites=true&w=majority",
function (err, client) {
if (err) {
console.log(err);
}
const db = client.db("todoapp");
app.post("/newpost", function (req, res) {
db.collection("counter").findOne(
{ name: "게시물 갯수" },
function (err, result) {
let totalPostCount = result.totalPost;
db.collection("post").insertOne(
{
_id: totalPostCount + 1,
제목: req.body.title,
날짜: req.body.date,
현재날짜시간: ${dateString} ${timeString}
,
},
function (err, result) {
console.log("저장완료");
db.collection("counter").updateOne(
{ name: "게시물 갯수" },
{ $inc: { totalPost: 1 } },
function () {}
);
}
);
}
);
res.redirect("/list");
});
.....
리다이렉트로 list 화면으로 넘어가면 방금 입력한 글이 확인되지 않고, 리스트 화면에서 새로 고침을 하여야 반영이 되는데,
해결 방법을 모르겠습니다