Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.6
    • Component/s: Querying
    • Labels:
    • Environment:
      All
    • Backwards Compatibility:
      Fully Compatible

      Description

      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 }
      

        Issue Links

          Activity

          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'coollog', u'name': u'Qingyang Chen', u'email': u'qingyang.chen@10gen.com'}

          Message: SERVER-3518 Tests for full code coverage in bit test query operators
          Branch: master
          https://github.com/mongodb/mongo/commit/d09c418c8b5fb5ccc7c2864cac8367d1f849bef1

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'coollog', u'name': u'Qingyang Chen', u'email': u'qingyang.chen@10gen.com'} Message: SERVER-3518 Tests for full code coverage in bit test query operators Branch: master https://github.com/mongodb/mongo/commit/d09c418c8b5fb5ccc7c2864cac8367d1f849bef1
          Hide
          neekfenwick Nick Fenwick added a comment -

          Not sure if this is on-topic, but how would we filter for this using the Expression syntax in C# using the official driver?

          e.g.
          Expression<Func<MongoThing, bool>> filter = f => f.bitfield & 128;
          var result = database
          .GetCollection<T>(CollectionName)
          .Find(filter);

          According to Properties on the MongoDB.Driver reference on our project we're using 2.0.1.27. In order to get bitwise support in Mongo I had to uninstall 3.0.6 from our Ubuntu 14.04 server and set up a 3.1 repository and install the mongodb-org-unstable* group of packages. How can we get a C# driver that also supports these new features?

          Show
          neekfenwick Nick Fenwick added a comment - Not sure if this is on-topic, but how would we filter for this using the Expression syntax in C# using the official driver? e.g. Expression<Func<MongoThing, bool>> filter = f => f.bitfield & 128; var result = database .GetCollection<T>(CollectionName) .Find(filter); According to Properties on the MongoDB.Driver reference on our project we're using 2.0.1.27. In order to get bitwise support in Mongo I had to uninstall 3.0.6 from our Ubuntu 14.04 server and set up a 3.1 repository and install the mongodb-org-unstable* group of packages. How can we get a C# driver that also supports these new features?
          Hide
          craiggwilson Craig Wilson added a comment -

          Hi Nick,

          We have a google groups list that is a great place to ask these types of questions.

          To answer you here, the current driver doesn't have strontly-typed support for this yet. It will be coming, likely in version 2.2 (which will line up with server 3.2). Until then, you can always construct this query manually using a BsonDocument...

          var filter = new BsonDocument("a", new BsonDocument("$bitsAllSet", 9));
          await collection.Find(filter).ToListAsync();
          

          Craig

          Show
          craiggwilson Craig Wilson added a comment - Hi Nick, We have a google groups list that is a great place to ask these types of questions. To answer you here, the current driver doesn't have strontly-typed support for this yet. It will be coming, likely in version 2.2 (which will line up with server 3.2). Until then, you can always construct this query manually using a BsonDocument... var filter = new BsonDocument("a", new BsonDocument("$bitsAllSet", 9)); await collection.Find(filter).ToListAsync(); Craig
          Hide
          rahbari Ali Rahbari added a comment - - edited

          I can understand why bitwise operator doesn’t utilize indexes, But I wonder if they are matched against an indexed field, the data in memory is used for comparison but a full table scan from storage is done?

          Show
          rahbari Ali Rahbari added a comment - - edited I can understand why bitwise operator doesn’t utilize indexes, But I wonder if they are matched against an indexed field, the data in memory is used for comparison but a full table scan from storage is done?
          Hide
          ramon.fernandez Ramon Fernandez added a comment -

          Ali Rahbari, this is indeed a limitation of this first implementation. Further work may include the use of indexes, but we haven't created a ticket for that yet – feel free to do so if you wish.

          Show
          ramon.fernandez Ramon Fernandez added a comment - Ali Rahbari , this is indeed a limitation of this first implementation. Further work may include the use of indexes, but we haven't created a ticket for that yet – feel free to do so if you wish.

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              37 weeks, 5 days ago
              Date of 1st Reply:

                Agile