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

Implement $nand Logical Query Operator

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • Querying
    • 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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            zammit.andrew@gmail.com Andrew Zammit
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated: