Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신동해
/
Omniscient-Public-Point-Of-View
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
4
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
신동해
2021-12-07 23:46:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c57e96df177ab8eca1bd53e221f857184e9c0490
c57e96df
1 parent
18108c14
Update server.js : add delete process
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
server.js
server.js
View file @
c57e96d
...
...
@@ -37,11 +37,31 @@ app.get('/write', function(요청, 응답){
app
.
post
(
'/add'
,
function
(
요청
,
응답
){
응답
.
send
(
'전송완료'
);
db
.
collection
(
'post'
).
insertOne
({
제목
:
요청
.
body
.
title
,
날짜
:
요청
.
body
.
date
},
function
(
에러
,
결과
){
db
.
collection
(
'counter'
).
findOne
({
name
:
'게시물갯수'
},
function
(
에러
,
결과
){
console
.
log
(
결과
.
totalPost
)
var
총게시물갯수
=
결과
.
totalPost
db
.
collection
(
'post'
).
insertOne
({
_id
:
총게시물갯수
+
1
,
제목
:
요청
.
body
.
title
,
날짜
:
요청
.
body
.
date
},
function
(
에러
,
결과
){
console
.
log
(
'저장완료'
)
// counter라는 콜렉션에 있는 totalPost라는 항목도 1 증가시켜야함
db
.
collection
(
'counter'
).
updateOne
({
name
:
'게시물갯수'
},{
$inc
:
{
totalPost
:
1
}
},
function
(){
if
(
에러
){
return
console
.
log
(
에러
)
}
})
});
});
});
app
.
get
(
'/list'
,
function
(
요청
,
응답
){
응답
.
render
(
'list.ejs'
);
// DB에 저장된 post라는 collectino안의 ~~인 데이터를 꺼내주세요
db
.
collection
(
'post'
).
find
().
toArray
(
function
(
에러
,
결과
){
console
.
log
(
결과
);
응답
.
render
(
'list.ejs'
,
{
posts
:
결과
});
})
});
app
.
delete
(
'/delete'
,
function
(
요청
,
응답
){
console
.
log
(
요청
.
body
)
})
\ No newline at end of file
...
...
Please
register
or
login
to post a comment