Add MongoDB $elemMatch equivalent for array field queries #13724
vqhdev
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
PayloadCMS currently lacks support for MongoDB's
$elemMatch
operator equivalent, which is essential for querying arrays where multiple conditions must match the same array element. This limitation significantly impacts complex data querying scenarios.Current Limitation
When querying array fields with multiple conditions, PayloadCMS treats each condition independently, which can return incorrect results. For example:
This query might return a product where:
size: 'L'
andcolor: 'blue'
size: 'M'
andcolor: 'red'
andinStock: true
Even though no single variant matches all three conditions.
Use Cases
This affects many real-world scenarios:
Proposed Solution
Add support for an
elemMatch
operator similar to MongoDB:Current Workarounds and Their Problems
Technical Considerations
Impact
This feature would:
References
$elemMatch
documentation: https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/This feature would significantly improve PayloadCMS query capabilities and make it more suitable for complex enterprise applications requiring precise array filtering.
Beta Was this translation helpful? Give feedback.
All reactions