Mongoose ile Veri Sorgulama ve Filtreleme
Temel CRUD işlemlerinin ötesine geçerek Mongoose'ta filtreler, işleçler, sıralama, sayfalama ve yansıtma kullanarak güçlü sorgular oluşturmayı öğrenin.
Mongoose ile Veri Sorgulama ve Filtreleme, CoddyKit'te ücretsiz bir Node.js Backend Development Bootcamp dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Node.js Backend Development Bootcamp öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Node.js Backend Development Bootcamp kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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/$gtegreater than (or equal)$lt/$lteless than (or equal)$nenot 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.
Sıkça Sorulan Sorular
“Mongoose ile Veri Sorgulama ve Filtreleme” dersi ücretsiz mi?
Evet — “Mongoose ile Veri Sorgulama ve Filtreleme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Node.js Backend Development Bootcamp kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Node.js Backend Development Bootcamp kursu toplamda 4 dersten oluşur.
“Mongoose ile Veri Sorgulama ve Filtreleme” dersinde ne öğreneceğim?
Temel CRUD işlemlerinin ötesine geçerek Mongoose'ta filtreler, işleçler, sıralama, sayfalama ve yansıtma kullanarak güçlü sorgular oluşturmayı öğrenin. Node.js Backend Development Bootcamp ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Node.js Backend Development Bootcamp öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Node.js Backend Development Bootcamp, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.
“Mongoose ile Veri Sorgulama ve Filtreleme” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Node.js Backend Development Bootcamp dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Node.js Backend Development Bootcamp dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Node.js'i MongoDB'ye Bağlama
- Veri Modellemede Mongoose ODM
- Mongoose ile CRUD İşlemleri
- Mongoose ile Veri Sorgulama ve Filtreleme