-
카테고리
-
세부 분야
풀스택
-
해결 여부
미해결
선생님! product 테이블에 컬럼이 일부 저장이 안됩니다
21.10.25 02:09 작성 조회수 108
0
선생님! 강의 너무 유용해요 잘 듣고있습니다~
그런데 마지막 부분에서 디비에 저장되는 컬럼에 body에서 보내준 내용 일부분만 저장이 되고 있습니다.
로그를 찍어봐도 body에는 정상적으로 잘 들어갔는데 오류 메세지도 없고.. 왜 이럴까요? 제가 누락한 부분이 있을까요..??
>client/UploadProductPage.js
const submitHandler = e => {
console.log("upload to DB");
e.preventDefault();
if (!TitleValue || !Description || !Price || !Continent || !Images) {
return alert("모든 값을 넣어주세요.");
}
const body = {
//로그인 된 사람의 ID를 넣어줘야 한다.
writer: props.user.userData._id,
title: TitleValue,
description: Description,
price: Price,
images: Images,
continents: Continent
};
Axios.post("/api/product", body).then(res => {
if (res.data.success) {
alert("상품 업로드에 성공했습니다.");
console.log(body);
props.history.push("/");
} else {
alert("상품 업로드에 실패했습니다.");
}
});
};
>server/model/Product.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const productSchema = mongoose.Schema(
{
writer: {
type: Schema.Types.ObjectId,
ref: "User"
},
title: {
type: String,
maxlength: 50
},
description: {
type: String
},
price: {
type: Number,
default: 0
},
images: {
type: Array,
default: []
},
sold: {
type: Number,
maxlength: 100,
default: 0
},
continents: {
type: Number,
default: 1
},
views: {
type: Number,
default: 0
}
},
{ timestamps: true }
);
productSchema.index(
{
title: "text",
description: "text"
},
{
weights: {
title: 5,
description: 1
}
}
);
const Product = mongoose.model("Product", productSchema);
module.exports = { Product };
>console.log 결과
>mongo DB 저장 결과
바쁘시겠지만 알려주시면 감사하겠습니다!
따라하며 배우는 노드, 리액트 시리즈 - 쇼핑몰 사이트 만들기[전체 리뉴얼]
모든 상품 정보를 데이터베이스에 저장하기[삭제 예정]
강의실 바로가기
답변을 작성해보세요.
0
John Ahn
지식공유자2021.10.25
안녕하세요 혀니님 !! 아마 백엔드에서 저장하는 부분을 봐야할 것 같은데
그부분을 올려주시겠어요?!!! 새로운 게시물에 그 부분이랑 전체 저장소 주소를 올려주시면 직접봐보겠습니다 !!
답변 2