-
글쓴이글
-
2021년 4월 19일 23:53 #8356
이종욱참가자강의 화면을 보니 데이터베이스 연결 코드에서 'mongodb+srv://codingapple:비번 ~ 으로 된 부분에서 앞 강의에서 연결 아디가 admin 이었던것 같은데 2강에서 codingapple로 바뀐 과정을 따라가지 못하겠습니다. 몇개 아이디를 조합해 봤는데 localhost:8080에서 정상 화면이 나오다 안나오다 하는데 mongodb 사이트 화면에는 데이터베이스 표시가 전혀 없습니다. 어떤 부분이 잘못 되었는지에 대한 고견 주시기 바랍니다. 수고하세요.
2021년 4월 20일 09:23 #8361
codingapple키 마스터연결하는 url엔 제거 따라쓰면 안되고 본인이 mongodb atlas에서 만든 디비접속용 아이디, 비번을 입력해주시면 됩니다
2021년 4월 20일 13:33 #8378
이종욱참가자const express = require('express');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended : true})); // ---질문---이 행의 bodyParser에 가로 줄이 단어 전체를 가운데로 가로질러 있습니다. 이부분에 대한 의견도 부탁드립니다.const MongoClient = require('mongodb').MongoClient;
var db;
MongoClient.connect('mongodb+srv://acepoker:93284547@cluster0.eqwrv.mongodb.net/myFirstDatabase?retryWrites=true&w=majority', function(에러, client){
//서버 뛰우는 코드 여기로 옮기기
if (에러) return console.log(에러)db = client.db('today');
db.collection('tomorrow').insertOne( {이름 : 'John', 나이 : 20} , function(에러, 결과){
console.log('저장완료');
});app.listen(8080, function(){
console.log('listening on 8080')
});});
app.listen(8080, function(){
console.log('listening on 8080')
});//누군가가 /pet로 방문을 하면..
//pet 관련되 안내문을 뛰워주자app.get('/pet', function(요청, 응답){
응답.send('펫용품 쇼핑할 수 있는 페이지입니다.');
});app.get('/beauty', function(요청, 응답){
응답.send('미용용품 쇼핑할 수 있는 페이지입니다.');
});app.get('/', function(요청, 응답){
응답.sendFile(__dirname + '/index.html')
});app.get('/write', function(요청, 응답){
응답.sendFile(__dirname + '/write.html')
});//어떤 사람이 /add 경로로 POST 요청을 하면..
//??를 해주세요~app.post('/add', function(요청, 응답){
응답.send('전송완료')
console.log(요청.body.date)
console.log(요청.body.title)
//DB에 저장 해주세요
});server.js 코드 전부입니다. 혹시 다른 코드도 필요하시거나 다른것이 필요하시면 알려 주시기 바랍니다. 수고하세요.
2021년 4월 20일 15:23 #8388
codingapple키 마스터저거 그대로 써보니까 접속 잘 된다고 나오는데요 테스트 게시물 저장완료도 잘 뜨고요
app.listen(8080, function(){
console.log(‘listening on 8080’)
});이거 두개 쓰셨는데 밑에건 하나 지워주십시오
bodyparser 줄쳐있는건 해당강의에 해결책 첨부했습니다
-
글쓴이글
- 답변은 로그인 후 가능합니다.