-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query Optimization
The following logical query operators exist: $and, $or, and $nor. There also exists $not, however this is a field-level operator, while the aforementioned are not field-specific.
I propose the introduction of a $nand operator as a compliment to $and, $or, and $nor.
Given the following query:
{ $and: [ {a: 1}, {b: 2} ] }
The current way to implement NAND logic:
{ $or: [ {'a': { $ne: 1} }, {'b': { $ne: 2} } ] }
This is problematic when an existing complex query exists (read: nested operators, mixed notation, etc.) and must be transformed. Before sending the query to MongoDB, it would have to be interpreted and the $ne operator strategically placed. It would be easier and less error-prone to use the existing query and wrap it in a $nand:
{ $nand: [ {a: 1}, {b: 2} ] }
Existing use cases are on Google Groups and StackOverflow.