MongoDB Atlas 검색 기능 구현하기 (진행중)

Joseph·2024년 2월 14일
  // 검색 쿼리 생성
  const query = { $text: { $search: searchWord } };

  const regexQuery = {
    $or: [
      { name: { $regex: searchWord, $options: 'i' } },
      { email: { $regex: searchWord, $options: 'i' } }
    ]
  };

    // 데이터 검색 및 결과를 배열로 변환
    const usersData = await db.collection("users").find(regexQuery).toArray().limit(10);

pagination 구현은 비교적 쉬우므로 바로 도입해야겠다

profile
안녕하세요 프론트와 백 둘다 관심있는 웹개발자 이창무입니다.

0개의 댓글