🔤
Querying & Filtering

Regex & Text Search

Pattern Matching
💡 Regex, queries, "WILDCARD, SEARCH" jaisi, HAIN — EXACT, WORD, DHOONDHNE, ke, BAJAYE, TUM, EK, PATTERN, (jaise, "naam, mein, 'aar', KAHI, BHI, ho") DHOONDH, sakte, HO.

$regex, OPERATOR, SE, PATTERN-BASED, MATCHING, ki, ja, sakti, hai — jaise, EK, NAAM, KISI, PARTICULAR, LETTER, SE, SHURU, hota, hai, YA, EK, SUBSTRING, CONTAIN, karta hai.

Text, SEARCH, index, banaake, ($text operator) FULL-TEXT, SEARCH, (WORD-LEVEL, RELEVANCE-BASED) ki, ja, sakti, hai — regex, se, ZYAADA, EFFICIENT, hai, LARGE, TEXT, FIELDS, ke, liye.

// Names jo "Aar" se, shuru, hote, hain (case-insensitive):
db.users.find({ name: { $regex: "^Aar", $options: "i" } });

// Text index banaна:
db.articles.createIndex({ content: "text" });

// Text search:
db.articles.find({ $text: { $search: "mongodb tutorial" } });
🔤
Regex, queries, "WILDCARD, SEARCH" jaisi, HAIN — EXACT, WORD, DHOONDHNE, ke, BAJAYE, TUM, EK, PATTERN, (jaise, "naam, mein, 'aar', KAHI, BHI, ho") DHOONDH, sakte, HO.
1 / 2
⚡ झट से Recap
  • $regex = pattern-based matching (substring, starts-with, etc.)
  • $text + text index = full-text, relevance-based, search
  • Regex, queries, generally, indexes, efficiently, use, nahi, kar, paate (except, starts-with)
इस page में (2 subtopics)

Text, index, banaते, waqt, DIFFERENT, fields, ko, DIFFERENT, "weights" diye, ja, sakte, hain — jaise, title, field, ko, HIGHER, weight, dena, taaki, title, mein, MATCH, hone, PAR, WOH, results, mein, ऊपर, RAHE, description, mein, match, hone, se.

db.articles.createIndex(
  { title: "text", content: "text" },
  { weights: { title: 10, content: 1 } }
);

{ $options: "i" } (case-insensitive) regex, queries, INDEXES, ka, EFFICIENTLY, use, NAHI, kar, paate — case-insensitive, search, ke, liye, EK, collation, WALA, index, ya, text, index, aksar, BEHTAR, PERFORMANCE, deta, hai.

💡Tip: Agar, case-insensitive, search, common, use-case, hai, EK, collation, {locale: "en", strength: 2} WALA, index, banaна, regex, se, MUCH, FASTER, ho, sakta hai.