Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1985

Additional overloads for BitsAllSet and other bitwise query operators

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.4.3
    • Component/s: Operations
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      SERVER-3518 introduced bitwise query operators with 3 different parameter types: a numeric bitmask (32-bit integer*), a BinData bitmask, or a position list (an array of 32-bit integers).

      However, the FilterDefinitionBuilder in the C# driver [only supports one overload for BitsAllSet](https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Driver/FilterDefinitionBuilder.cs#L321) (and other binary operators): a 64-bit long. This becomes an issue if you want to do a bitwise query on more than 64 bits, as there's no overload to allow you to pass in that amount of data. I've been able to work around this for now by simply building a BsonDocument containing my query, which simply converts an IEnumerable<int> to a BsonArray field value.

      IEnumerable<int> bitPositions = new [] { 148, 149, 150, 151, 152 };
      var queryDocument = new BsonDocument
      {
          { "binaryDataField", new BsonDocument {
              { "$bitsAllSet", new BsonArray(bitPositions) }
          }}
      };
      

      While this works, it's a pain to get it to work with other FilterDefinitions, and it requires that you pull the BsonElementName off of your model class, which isn't really a great solution for maintainability. I would like to see support for the BinData (as byte[]) and position list (as IEnumerable<int>) overloads added to the BitsAllSet, BitsAllClear, BitsAnySet, and BitsAnyClear methods of FilterDefinitionBuilder.

      • Through testing, I've found that the actual maximum for the numeric bitmask is 0x7FFFFFFFFFFFFDFF through mongo shell, and long.MaxValue through the C# driver.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmbrogan Jacob Brogan
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: