Skip to content

MONGOID-5030 Short-circuit trivial queries where $in is given an empty array#6138

Merged
jamis merged 1 commit intomongodb:masterfrom
jamis:5030-short-circuit-queries
Apr 24, 2026
Merged

MONGOID-5030 Short-circuit trivial queries where $in is given an empty array#6138
jamis merged 1 commit intomongodb:masterfrom
jamis:5030-short-circuit-queries

Conversation

@jamis
Copy link
Copy Markdown
Contributor

@jamis jamis commented Apr 23, 2026

Summary

When Mongoid.allow_short_circuit_queries == true, any top-level $in query condition that evaluates to an empty array will cause the query to be short-circuited, returning an empty array without sending the query to the database.

Mongoid.allow_short_circuit_queries = true
Document.in([]) #=> empty array, no database query issued

Mongoid.allow_short_circuit_queries = false
Document.in([]) #=> empty array, one database query issued

The Mongoid.allow_short_circuit_queries setting defaults to false.

@jamis jamis added the feature Adds a new feature, without breaking compatibility label Apr 23, 2026
@jamis jamis requested a review from a team as a code owner April 23, 2026 21:09
@jamis jamis requested review from comandeo-mongo and Copilot and removed request for Copilot April 23, 2026 21:09
@jamis jamis merged commit f178538 into mongodb:master Apr 24, 2026
76 checks passed
@jamis jamis deleted the 5030-short-circuit-queries branch April 24, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Adds a new feature, without breaking compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants