안녕하세요, 코딩애플 강의를 수강하고 있습니다.
Node.js , MongoDB 를 이용해 두시간만에 빠르게 웹서비스 만들기를 수강하고 있는데요,
Part2 데이터베이스에 자료 저장하는법 챕터에서 막혀서 진행하지 못하고 있습니다.
몽고 db 연결해서 데이터를 저장하는 부분을 진행하고 있는데
(node:35880) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
listening on 8080
저장완료
aaaaaaaaaaa
이처럼, submit 버튼 눌렀을때 input에 넣은 값이 콘솔창에 뜨고 저장완료 로그가 뜨는것까지는 구현이 되었씁니다.
그런데 몽고 db에 데이터가 쌓이지 않고 변화가 없습니다.
메시지가 뜨는데 저장된 데이터가 몽고 db atlas에 저장되지 않습니다.
어떤 부분을 수정해야 하는지 궁금합니다 ㅜㅜ
서버 코드는 아래와 같이 작성하였습니다
const express = require('express');
const app = express();
const bodyParser= require('body-parser')
app.use(bodyParser.urlencoded({extended: true}));
const MongoClient = require('mongodb').MongoClient;
var db;
MongoClient.connect('mongodb+srv://doosan0425:QWER1234@cluster0.kghy9ha.mongodb.net/todoapp?retryWrites=true&w=majority', { useUnifiedTopology: true }, function(에러,client) {
//연결되면 할일
if (에러) return console.log(에러)
db = client.db('todoapp');
db.collection('post').insertOne( {이름 : 'John', _id : 100} , function(에러, 결과) {
console.log('저장완료');
});
app.listen(8080, function() {
console.log('listening on 8080')
});
});
app.get('/write',function (요청, 응답) {
응답.sendFile(__dirname + '/write.html')
});
app.post('/add', function (요청, 응답) {
응답.send('전송완료');
console.log(요청.body.date);
console.log(요청.body.title);
});