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

Bitwise query operators

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.6
    • Affects Version/s: None
    • Component/s: Querying
    • Environment:
      All
    • Fully Compatible
    • Quint Iteration 6

      We've decided to implement a few bit-test query operators:

      $bitsAllSet - matches if the input bit positions are all 1
      $bitsAllClear - matches if the input bit positions are all 0
      $bitsAnySet - matches if any of the bit positions are 1
      $bitsAnyClear - matches if any of the bit positions are 0

      These operators can take an array of bit positions, a 64-bit number bitmask, or a BinData bitmask. For the number and BinData bitmasks, the bit positions to check are the positions of 1's in their binary representation.

      The operators will only match against int32, int64, doubles, and binary data. Other types will not match.

      Note that bit position 0 means the least significant bit.

      An example using the array of bit positions syntax:

      db.foo.insert( { a: 43 } ); // Binary form: 101011 (leading zeroes truncated)
      db.foo.find( { a: { $bitsAllSet: [0, 1, 3] } }, { _id: 0, a: 1 } );
      Result: { a: 43 }
      

      An example using the bitmask syntax:

      db.foo.insert( { a: 43 } ); // Binary form: 101011 (leading zeroes truncated)
      db.foo.find( { a: { $bitsAllSet: 9 } }, { _id: 0, a: 1 } ); // Binary form of the bitmask: 1001
      Result: { a: 43 }
      

            Created:
            Updated:
            Resolved: