-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
제목
게시글 검색 API 개발
수정파일
상세내용
router.get("/searchpost", async (req, res) => {
let options = []
if (req.query.option == "title") {
options = [{ title: new RegExp(req.query.content) }]
} else if (req.query.option == "content") {
options = [{ content: new RegExp(req.query.content) }]
} else if (req.query.option == "title+content") {
options = [
{ title: new RegExp(req.query.content) },
{ content: new RegExp(req.query.content) },
]
} else {
const err = new Error("검색 옵션이 없습니다.")
err.status = 400
throw err
}
const post = await posts.find({ $or: options })
return post
})
오류가 발생하는데 API 주소에서 계속 나오네요.
게시글 가져오는 api랑 뭐가 겹치는 거 같은데
"Cast to Number failed for value "NaN" (type number) at path "postid" for model "post""
-> 해결
post를 받아오고 콜백함수로 send를 보내지 않아서 실패햇었음.