
웹소켓에 쓴 댓글들을 몽고 DB에 저장하려고합니다.
기존에 배웠던 app.post / app.get 외 구글 어쩌구저쩌구에 찾아봐도 자꾸 오류뜨고 몽고 DB 에 아무것두 저장이 안됩ㄴ디ㅏ..
[ .ejs ]
<!--<script>
$('.btn-plus').click(function(e){
var _id = e.target.dataset.id;
$.post('/chatroom', {게시글번호 : _id})
.then(()=>{
console.log('완료')
})
});
</script>-->
[server.js]
app.post('/list2', function (요청, 응답) {
응답.render('list2.ejs')
db.collection('chatroom1').findOne(), function(에러, 결과){
var post = { 제목: 요청.body.title, 댓글 : 요청.body.chat }
db.collection('post').insertOne( post , function (에러, 결과) {
db.collection('chatroom1'),function(에러, 결과){
if(에러){return console.log(에러)}
})
}});