리뷰 기능을 만들고 있는데 post 요청시 자료가 조금 이상하게 저장되어서 선생님께 질문드립니다!
가르쳐 주신대로 게시물 번호를 달아서 저장했는데 저장하려는 내용이 key 이고 '' '' 가 value 인 object 가 저장되고 맙니다
제가 useState 를 사용해 초기값을 '' 로 빈 스트링을 저장해서 그런 것 같은데 해답이 잘 떠오르지가 않습니다
어떻게 하면 이를 해결할 수 있을까요?
아래는 버튼을 누르면 e.target.value인 리뷰 state를 post 요청하는 코드입니다
const [리뷰, 리뷰변경] = useState('');
<Container className="col-md-8"><div className="product-box">
<RatingIt></RatingIt>
<InputGroup className="mt-1"
onChange={(e)=>{
e.preventDefault();
리뷰변경(e.target.value)}}>
<Form.Control className="m-3" as="textarea" rows={6}
placeholder="어떤 점이 귀여웠나요? 별점과 함께 10자 이상 작성해주세요!" />
</InputGroup>
<button className="buttonBlue mb-2" role="button" type="submit"
onClick={() => {
axios.post("/review", 리뷰).then((결과)=>console.log(결과)).catch(()=>console.log(리뷰))
}}
>
제출하기
</button>
</div></Container>
그리고 아래 사진처럼 이런 식으로 자료가 저장되고 있습니다
아래는 server.js 의 코드입니다
app.post('/review', function(요청, 응답){
db.collection('ReviewCount').findOne({name : '게시물개수'}, function(에러, 결과){
var 총게시물개수 = 결과.totalPost;
db.collection('ReviewCount').updateOne( {name : '게시물개수' } , { $inc : { totalPost : 1 } } , function(에러, 결과){
db.collection('Review').insertOne( { _id : (총게시물개수 + 1), 내용 : 요청.body } , function(){
console.log('저장완료')
응답.send('전송완료');
});
})
});
});