Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-15577

Implement $nand Logical Query Operator

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      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.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            zammit.andrew@gmail.com Andrew Zammit
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: