Quick Answer
$near and $geoNear for geospatial queries require a 2dsphere or 2d index. Performance trade-offs: they sort results by distance (expensive for large result sets), can't be combined efficiently with other indexes (geospatial index used, other filters applied after), and $near doesn't work in aggregation pipelines ($geoNear must be first stage). Limit results to a reasonable maxDistance and document count.
Answer
$near provides distance-ordered results but can be CPU-heavy and require specialized indexes for performance.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
MongoDB interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Perfect for freshers and experienced candidates.