Create a text index: schema.index({ title: 'text', body: 'text' }). Then query: Post.find({ $text: { $search: 'nodejs developer' } }). Add a text index only on fields you search; it is heavy.
MongoDB Query Operators for Node.js Developers
How do I do full-text search in MongoDB?
The answer
More FAQs in MongoDB Query Operators for Node.js Developers
Comparison ($eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists), logical ($and, $or, $nor, $not), element ($exists, $type), array ($all, $elemMatch, $size), and evaluation ($regex, $text, $where).
Use $gte and $lte with Date objects: User.find({ createdAt: { $gte: new Date('2025-01-01'), $lt: new Date('2025-02-01') } }). Always use Date objects, not strings.
User.find({ skills: 'node' }). For multiple values, use $all: User.find({ skills: { $all: ['node', 'react'] } }). For at least one of multiple, use $in: User.find({ skills: { $in: ['node', 'react'] } }).
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.