Details
-
New Feature
-
Resolution: Unresolved
-
Minor - P4
-
None
-
None
-
None
-
Query Optimization
Description
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.