[SERVER-15577] Implement $nand Logical Query Operator Created: 09/Oct/14  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Andrew Zammit Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Optimization
Participants:

 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.



 Comments   
Comment by Asya Kamsky [ 10/Oct/16 ]

The exact equivalent can be achieved by just adding "$nor" around the "$and" expression:

{
     $nor: [
       {
         $and: [
             {a: 1},
             {b: 2}
         ]
       }
    ]
}

Generated at Thu Feb 08 03:38:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.