• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 post요청한 데이터가 몽고db에 저장되지 않는 현상

post요청한 데이터가 몽고db에 저장되지 않는 현상

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #44144

    백두산
    참가자

    안녕하세요, 코딩애플 강의를 수강하고 있습니다.

    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);
    });
     
     
    #44166

    codingapple
    키 마스터
     db.collection('post').insertOne( {이름 : 'John', _id : 100} , 
    이거는 테스트용으로 해본거라 1개 저장되면 잘된겁니다 
    지우고 계속 진행하면 됩니다
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠