3 글 보임 - 1 에서 3 까지 (총 3 중에서)
-
글쓴이글
-
2023년 5월 3일 18:28 #80747
양정민참가자HTML에 DB데이터 꽂아넣는 법 1강의에서 저번시간 숙제 중
const express = require('express'); const app = express(); const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({extended : true}));
const { MongoClient, ServerApiVersion } = require('mongodb'); const uri = "mongodb+srv://harinworld95:bC7HiRIwJi3Aueap@cluster0.yl5buva.mongodb.net/?retryWrites=true&w=majority";
const client = new MongoClient(uri, { serverApi: { version: ServerApiVersion.v1, strict: true, deprecationErrors: true, } });
async function run() { try { await client.connect(); await client.db("node-todoapp").collection("post").insertOne({name: 'John', 나이: 20}); console.log('저장완료'); } finally { await client.close(); } } run().catch(console.dir);
app.listen(8080, function(){ console.log('listening on 8080'); }); app.post('/add', (요청, 응답)=>{ 응답.send('전송완료'); client.db("node-todoapp").collection("post").insertOne({ 제목 : 요청.body.title, 날짜 : 요청.body.date}, (에러, 결과)=>{ console.log('저장완료'); }); })
이렇게 작성하였는데 [nodemon] app crashed - waiting for file changes before starting... 이러한 에러가 뜹니다.. 어떻게 해야할까요?
2023년 5월 3일 18:29 #80748
양정민참가자/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:23 throw new error_1.MongoNotConnectedError('Client must be connected before running operations'); ^
MongoNotConnectedError: Client must be connected before running operations at executeOperationAsync (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:23:19) at /Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:12:45 at maybeCallback (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/utils.js:263:21) at executeOperation (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/operations/execute_operation.js:12:38) at Collection.insertOne (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/mongodb/lib/collection.js:145:57) at /Users/yangjeongmin/Documents/node.js/todoapp/server.js:48:50 at Layer.handle [as handle_request] (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/layer.js:95:5) at next (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/yangjeongmin/Documents/node.js/todoapp/node_modules/express/lib/router/layer.js:95:5) { [Symbol(errorLabels)]: Set(0) {} }
Node.js v18.12.1 [nodemon] app crashed - waiting for file changes before starting...
오류 전문입니다.!
-
글쓴이글
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
- 답변은 로그인 후 가능합니다.