Text Search in MongoDB

From the MongoDB cheat sheet · Query Operators · verified Jul 2026

Text Search

Full-text search capabilities

javascript
// Create text index first
db.articles.createIndex({ 
  title: "text", 
  content: "text" 
})

// Basic text search
db.articles.find({ 
  $text: { $search: "mongodb tutorial" }
})

// Exact phrase search
db.articles.find({ 
  $text: { $search: '"exact phrase"' }
})

// Exclude terms
db.articles.find({ 
  $text: { $search: 'mongodb -sql' }
})
💡 Text index required for $text search
📌 $text searches all indexed fields
⚡ Text indexes can be large - use wisely
⚠️ Only one text index per collection
🔗 Consider Atlas Search for advanced needs
querysearchtext

More MongoDB tasks

Back to the full MongoDB cheat sheet