-
Type: New Feature
-
Resolution: Won't Fix
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.4.3
-
Component/s: Operations
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.