7 글 보임 - 1 에서 7 까지 (총 7 중에서)
-
글쓴이글
-
2023년 7월 25일 00:11 #92209
김진호참가자{ value: 'undefined' } 계속 이렇게 떠서 검색하고나면 list에 아무것도 나오지않습니다. search.ejs <div class="container input-group mb-2"> <input class="form-control" id="search-input"> <button class="input-group-append btn btn-danger" id="search">검색</button> </div>
<!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script> $('#search').click(function(){ var 입력한값 = $('#search-input').val(); window.location.replace('/search?value='+ 입력한값) }); </script>
<div class="'container" <h4 class="ml-2 my-3 text-center"></h4> <ul class="list-group"> <% for (var i = 0; i < posts.length; i++){ %> <li class="list-group-item"> <p>글번호 : <%= posts[i]._id %> </p> <h4> 할일 제목 : <%= posts[i].제목 %> </h4> <p> 할일 마감날짜 : <%= posts[i].날짜 %> </p> <button class="btn btn-danger delete" data-id="<%= posts[i]._id %>">삭제</button> <% } %> </div>
========================================================== server.js app.get('/search', (요청, 응답)=>{ console.log(요청.query); var 검색조건 = [ { $search: { index: 'titleSearch', text: { query: 요청.query.value, path: '제목' // 제목날짜 둘다 찾고 싶으면 ['제목', '날짜'] } } }, // { $sort : { _id : 1 } }, // { $limit : 10 }, // { $project : { 제목 : 1, _id : 0, score:{$meta:"searchScore"} } } ] db.collection('post').aggregate(검색조건).toArray((에러, 결과)=>{ console.log(결과) 응답.render('search.ejs', {posts : 결과}) }) })
2023년 7월 25일 09:29 #92232
codingapple키 마스터요청.query가 undefined 나오는거면 페이지 이동을 잘못한듯요 검색어 잘 입력하고 검색버튼눌렀나요
2023년 7월 25일 19:21 #92312
codingapple키 마스터ejs 파일에 id="search-input" id="search" 다른데 또 있나 확인해보거나 크롬콘솔창에 에러안뜨나 확인해봅시다
2023년 7월 25일 21:49 #92335
김진호참가자에러는 하나도 안뜨고 app.get('/search', (요청, 응답)=>{ console.log(요청.query); var 검색조건 = [ { $search: { index: 'titleSearch', text: { query: 요청.query.value, path: '제목' // 제목날짜 둘다 찾고 싶으면 ['제목', '날짜'] } } }, // { $sort : { _id : 1 } }, // { $limit : 10 }, // { $project : { 제목 : 1, _id : 0, score:{$meta:"searchScore"} } } ] db.collection('post').aggregate(검색조건).toArray((에러, 결과)=>{ console.log(결과) 응답.render('search.ejs', {posts : 결과}) }) })
-
글쓴이글
7 글 보임 - 1 에서 7 까지 (총 7 중에서)
- 답변은 로그인 후 가능합니다.