How do I query where an array contains a value in MongoDB?
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'] } }).
Verify This Answer
Cross-check this information using these trusted sources:
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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
