0Pricing
Node.js Backend Development Bootcamp · 강의

Mongoose로 데이터 조회 및 필터링

기본적인 CRUD를 넘어 필터, 연산자, 정렬, 페이지 매김, 프로젝션을 사용해 Mongoose에서 강력한 조회를 만드는 방법을 배웁니다.

Mongoose로 데이터 조회 및 필터링은(는) CoddyKit의 무료 Node.js Backend Development Bootcamp 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Node.js Backend Development Bootcamp 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Beyond Find-All

Fetching every document with Model.find() works for tiny collections, but real apps need to filter, sort, limit, and shape their results.

Mongoose gives you a fluent query API that mirrors MongoDB's query language.

const users = await User.find({ active: true });

Filtering by Field

Pass an object to find() to match documents by exact field values. Multiple keys are combined with logical AND.

const admins = await User.find({ role: 'admin', active: true });

Comparison Operators

MongoDB operators start with $. The most common comparisons are:

  • $gt / $gte greater than (or equal)
  • $lt / $lte less than (or equal)
  • $ne not equal
const adults = await User.find({ age: { $gte: 18 } });

Matching Multiple Values

Use $in to match any value from a list, and $nin to exclude a list. This is cleaner than chaining many OR conditions.

const team = await User.find({ role: { $in: ['admin', 'editor'] } });

Logical OR

The $or operator takes an array of conditions; a document matches if any one is true.

const results = await User.find({
  $or: [{ city: 'Berlin' }, { city: 'Paris' }]
});

Sorting Results

Chain .sort() to order results. Use 1 for ascending and -1 for descending. You can sort by multiple fields.

const recent = await User.find().sort({ createdAt: -1, name: 1 });

Limiting and Skipping

Pagination relies on .limit() (max documents) and .skip() (how many to bypass). For page 2 with 10 per page, skip 10 and limit 10.

const page = 2, perPage = 10;
const items = await User.find()
  .skip((page - 1) * perPage)
  .limit(perPage);

Selecting Specific Fields

Use .select() (projection) to return only the fields you need. Prefix a field with - to exclude it. This reduces payload size and hides sensitive data.

const safe = await User.find().select('name email -_id');
const noPass = await User.find().select('-password');

Finding a Single Document

findOne() returns the first match or null. findById() is a shortcut for matching by _id.

const user = await User.findOne({ email: 'a@b.com' });
const byId = await User.findById('652f1c...');

Counting Documents

To know how many documents match a filter without fetching them all, use countDocuments(). This is essential for showing total pages in pagination.

const total = await User.countDocuments({ active: true });
console.log('Active users:', total);

Text & Regex Search

For partial matches, use a regular expression. The $regex operator with the i option makes a case-insensitive search.

const matches = await User.find({
  name: { $regex: 'an', $options: 'i' }
});

Quick Check

Test your Mongoose querying skills.

Recap

You can now build rich Mongoose queries:

  • Filter by field and combine with operators like $gte, $in, $or
  • Order results with .sort()
  • Paginate with .skip() and .limit()
  • Shape output with .select()
  • Count matches with countDocuments()

These tools turn a basic data layer into a flexible, production-ready API.

자주 묻는 질문

“Mongoose로 데이터 조회 및 필터링” 강의는 무료인가요?

네 — “Mongoose로 데이터 조회 및 필터링” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Node.js Backend Development Bootcamp 강의 전체를 잠금 해제할 수 있습니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

“Mongoose로 데이터 조회 및 필터링”에서 뭘 배우나요?

기본적인 CRUD를 넘어 필터, 연산자, 정렬, 페이지 매김, 프로젝션을 사용해 Mongoose에서 강력한 조회를 만드는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Node.js Backend Development Bootcamp을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Node.js Backend Development Bootcamp을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Node.js Backend Development Bootcamp은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“Mongoose로 데이터 조회 및 필터링” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Node.js Backend Development Bootcamp 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Node.js Backend Development Bootcamp 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Node.js를 MongoDB에 연결하기
  2. 데이터 모델링을 위한 Mongoose ODM
  3. Mongoose로 CRUD 작업하기
  4. Mongoose로 데이터 조회 및 필터링
← Node.js Backend Development Bootcamp(으)로 돌아가기