8 글 보임 - 1 에서 8 까지 (총 8 중에서)
-
글쓴이글
-
2022년 9월 23일 20:37 #47545
코딩이참가자(node:61036) UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: todoapp.post index: _id_ dup key: { _id: 1 } at Function.create (C:\todoapp\node_modules\mongodb\lib\core\error.js:57:12) at toError (C:\todoapp\node_modules\mongodb\lib\utils.js:123:22) at C:\todoapp\node_modules\mongodb\lib\operations\common_functions.js:258:39 at handler (C:\todoapp\node_modules\mongodb\lib\core\topologies\replset.js:1210:22) at C:\todoapp\node_modules\mongodb\lib\core\connection\pool.js:405:18 at processTicksAndRejections (internal/process/task_queues.js:79:11) (node:61036) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:61036) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. PS C:\todoapp> node server.js Debugger attached. (node:47044) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor. listening on 8080 저장완료 11 11 0 저장완료 11 11 저장완료 0 (node:47044) UnhandledPromiseRejectionWarning: MongoError: E11000 duplicate key error collection: todoapp.post index: _id_ dup key: { _id: 1 } at Function.create (C:\todoapp\node_modules\mongodb\lib\core\error.js:57:12) at toError (C:\todoapp\node_modules\mongodb\lib\utils.js:123:22) at C:\todoapp\node_modules\mongodb\lib\operations\common_functions.js:258:39 at handler (C:\todoapp\node_modules\mongodb\lib\core\topologies\replset.js:1210:22) at C:\todoapp\node_modules\mongodb\lib\core\connection\pool.js:405:18 at processTicksAndRejections (internal/process/task_queues.js:79:11) (node:47044) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) 이렇게 뜨면서 0은 출력이 잘되는데 1부터 출력이 안되네요 조언을 구합니다 (node:47044) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2022년 9월 24일 09:00 #47585
코딩이참가자여기 제 server.js 코드입니다
const express = require("express"); const app = express(); const bodyParser = require("body-parser"); app.use(bodyParser.urlencoded({ extended: true })); const MongoClient = require("mongodb").MongoClient;
app.set("view engine", "ejs");
var db; MongoClient.connect( "mongodb+srv://gihwan:@atlascluster.u961rpo.mongodb.net/?retryWrites=true&w=majority", function (err, client) { if (err) return console.log(err);
db = client.db("todoapp");
db.collection("post").insertOne( { 제목: "코딩애플", 날짜: "2022년 9월 22일" }, function (err, res) { console.log("저장완료"); } );
app.listen(8080, function () { console.log("listening on 8080"); }); } );
app.get("/pet", function (req, res) { res.send("반갑습니다"); });
app.get("/beauty", function (req, res) { res.send("고맙습니다"); });
app.get("/", function (req, res) { res.sendFile(__dirname + "/write.html"); }); app.get("/index", function (req, res) { res.sendFile(__dirname + "/index.html"); });
app.post("/add", function (req, res) { console.log(req.body.title); console.log(req.body.date); db.collection("counter").findOne( { name: "게시물갯수" }, function (err, result) { console.log(result.totalPost); var 총게시물갯수 = result.totalPost;
db.collection("post").insertOne({ _id: 총게시물갯수 + 1, 제목: req.body.title, 날짜: req.body.date, }); } );
db.collection("post").insertOne( { 제목: req.body.title, 날짜: req.body.date }, function (err, res) { console.log("저장완료"); } );
res.send("전송완료"); });
app.get("/list", function (요청, 응답) { db.collection("post") .find() .toArray(function (에러, 결과) { console.log(결과); 응답.render("list.ejs", { posts: 결과 }); }); }); 감사합니다
-
글쓴이글
8 글 보임 - 1 에서 8 까지 (총 8 중에서)
- 답변은 로그인 후 가능합니다.