@@ -70,9 +70,9 @@ as follows:
70
70
.. code-block:: csharp
71
71
:emphasize-lines: 3
72
72
73
- var restaurantsDatabase = client.GetDatabase("sample_restaurants");
74
- var restaurantsCollection = restaurantsDatabase.GetCollection<Restaurant>("restaurants");
75
- var queryableCollection = restaurantsCollection.AsQueryable();
73
+ var restaurantsDatabase = client.GetDatabase("sample_restaurants");
74
+ var restaurantsCollection = restaurantsDatabase.GetCollection<Restaurant>("restaurants");
75
+ var queryableCollection = restaurantsCollection.AsQueryable();
76
76
77
77
The ``AsQueryable()`` method returns an `IMongoQueryable
78
78
<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Linq.IMongoQueryable.html>`__ instance that
@@ -591,12 +591,17 @@ in the Atlas manual and select :guilabel:`C#` from the language dropdown.
591
591
Bitwise Operators
592
592
~~~~~~~~~~~~~~~~~
593
593
594
- This version of the {+driver-short+} supports the following bitwise operators in
595
- the aggregation pipeline. You can use multiple bitwise operators within the same
596
- stage. All operands must be of type ``int`` or ``long``. ``$bitAnd``, ``$bitOr``,
594
+ The {+driver-short+} supports the use of the following
595
+ `bitwise operators <https://en.wikipedia.org/wiki/Bitwise_operation>`__ in the
596
+ aggregation pipeline. You can use multiple bitwise operators in the same
597
+ stage. The following limits apply when using bitwise operators:
598
+
599
+ All operands must be of type ``int`` or ``long``. ``$bitAnd``, ``$bitOr``,
597
600
and ``$bitXor`` all take two or more operands. ``$bitNot`` can only take one
598
601
operand.
599
602
603
+ The bitwise operation will be evaluated from left to right.
604
+
600
605
The examples for this section use the following documents in a collection called
601
606
``ingredients``:
602
607
@@ -625,36 +630,35 @@ collection:
625
630
public int Count { get; set; }
626
631
}
627
632
628
- .. note::
629
-
630
- For all bitwise operators, if the operand list contains a missing or undefined
631
- value, the entire expression evaluates to ``null``.
633
+ .. note:: Missing or Undefined Operands
632
634
635
+ If the operand list you pass to any bitwise operator contains a missing or
636
+ undefined value, the entire expression evaluates to ``null``.
633
637
634
638
$bitAnd
635
639
+++++++
636
640
637
- The ``$bitAnd`` aggregation stage performs a bitwise AND operation on the given
638
- arguments. The following example shows how to generate a ``$bitAnd`` stage using
639
- LINQ:
641
+ The ``$bitAnd`` aggregation operator performs a bitwise AND operation on the given
642
+ arguments. You can use the ``$bitAnd`` operator by connecting two or more
643
+ clauses with a ``&`` character. The following example shows how to create a
644
+ ``$bitAnd`` stage using LINQ:
640
645
641
646
.. code-block:: csharp
642
647
643
- var query = queryableCollection.AsQueryable()
648
+ var query = queryableCollection
644
649
.Where(i => i.Name == "eggs")
645
650
.Select(i => i.Price & i.Count);
646
651
647
- The preceding example finds the document where the ``Name`` field has the value
648
- ``"eggs"``. It then performs a bitwise AND operation on the values of the
649
- ``Price`` and ``Count`` fields in this document. The result contains one value:
650
- ``4``.
652
+ The preceding example retrieves the document in which the ``Name`` field has the
653
+ value ``"eggs"``. It then performs a bitwise AND operation on the values of the
654
+ ``Price`` and ``Count`` fields in this document, returning a value of ``4``.
651
655
652
656
The following example performs the same bitwise AND operation, but on all
653
657
documents in the collection:
654
658
655
659
.. code-block:: csharp
656
660
657
- var query = queryableCollection.AsQueryable()
661
+ var query = queryableCollection
658
662
.Select(i => i.Price & i.Count);
659
663
660
664
The result of the preceding example contains the following values:
@@ -675,30 +679,33 @@ the expression evaluates to ``null``.
675
679
$bitOr
676
680
++++++
677
681
678
- The ``$bitOr`` aggregation stage performs a bitwise OR operation on the given
679
- arguments. The following example shows how to generate a ``$bitOr`` stage using
680
- LINQ:
682
+ The ``$bitOr`` aggregation operator performs a bitwise OR operation on the given
683
+ arguments. You can use the ``$bitOr`` operator by connecting two or more
684
+ clauses with a ``|`` character. The following example shows how to create a
685
+ ``$bitOr`` stage using LINQ:
681
686
682
687
.. code-block:: csharp
683
688
684
- var query = queryableCollection.AsQueryable()
689
+ var query = queryableCollection
685
690
.Where(i => i.Name == "eggs")
686
691
.Select(i => i.Price | i.Count);
687
692
688
- The preceding example finds the document where the ``Name`` field has the value
689
- ``"eggs"``. It then performs a bitwise OR operation on the values of the
690
- ``Price`` and ``Count`` fields in this document. The result contains one value:
693
+ The preceding example retrieves the document in which the ``Name`` field has the
694
+ value ``"eggs"``. It then performs a bitwise OR operation on the values of the
695
+ ``Price`` and ``Count`` fields in this document, returning the value
691
696
``13``.
692
697
693
698
$bitNot
694
699
+++++++
695
700
696
- The ``$bitNot`` aggregation stage performs a bitwise NOT operation on the given
697
- argument. ``$bitNot`` only takes one argument.
701
+ The ``$bitNot`` aggregation operator performs a bitwise NOT operation on the given
702
+ argument. You can use the ``$bitNot`` operator by preceding an
703
+ operand with a ``~`` character. ``$bitNot`` only takes one argument. The
704
+ following example shows how to create a ``$bitNot`` stage using LINQ:
698
705
699
706
.. code-block:: csharp
700
707
701
- var queryable = collection.AsQueryable()
708
+ var queryable = collection
702
709
.Select(i => ~i.Count);
703
710
704
711
The result of the preceding example contains the following values:
@@ -715,22 +722,21 @@ The result of the preceding example contains the following values:
715
722
$bitXor
716
723
+++++++
717
724
718
- The ``$bitXor`` aggregation stage performs a bitwise XOR operation on the given
719
- arguments.
720
-
721
- The following example shows how to generate a ``$bitXor`` stage using
722
- LINQ:
725
+ The ``$bitXor`` aggregation operator performs a bitwise XOR operation on the given
726
+ arguments. You can use the ``$bitXor`` operator by connecting two or more
727
+ clauses with a ``^`` character. The following example shows how to create a
728
+ ``$bitXor`` stage using LINQ:
723
729
724
730
.. code-block:: csharp
725
731
726
- var query = queryableCollection.AsQueryable()
732
+ var query = queryableCollection
727
733
.Where(i => i.Name == "eggs" || i.Name == "watermelon")
728
734
.Select(i => i.Price ^ i.Count);
729
735
730
- The preceding example finds the documents where the ``Name`` field has the value
731
- ``"eggs"`` or ``"watermelon"``. It then performs a bitwise OR operation on the
732
- values of the ``Price`` and ``Count`` fields in these documents. The result
733
- contains the following values:
736
+ The preceding example retrieves the documents in which the ``Name`` field has
737
+ the value ``"eggs"`` or ``"watermelon"``. It then performs a bitwise XOR
738
+ operation on the values of the ``Price`` and ``Count`` fields in these
739
+ documents. The result contains the following values:
734
740
735
741
.. code-block:: json
736
742
0 commit comments