@@ -588,52 +588,114 @@ in the Atlas manual. For more examples about running Atlas Vector Search queries
588
588
{+driver-short+}, see :atlas:`Run Vector Search Queries </atlas-vector-search/vector-search-stage/>`
589
589
in the Atlas manual and select :guilabel:`C#` from the language dropdown.
590
590
591
+ Bitwise Operators
592
+ ~~~~~~~~~~~~~~~~~
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``,
597
+ and ``$bitXor`` all take two or more operands. ``$bitNot`` can only take one
598
+ operand.
599
+
600
+ The examples for this section use the following documents in a collection called
601
+ ``ingredients``:
602
+
603
+ .. code-block:: json
604
+
605
+ { "_id": 1, "name": "watermelon", "price": 5, "count": 1 },
606
+ { "_id": 2, "name": "onions", "price": 2, "count": 4 },
607
+ { "_id": 3, "name": "eggs", "price": 5, "count": 12 },
608
+ { "_id": 4, "name": "potatoes", "price": 3, "count": 0 },
609
+ { "_id": 5, "name": "pasta", "price": 4, "count": 100 },
610
+ { "_id": 6, "name": "cheese", "price": 4 }
611
+
612
+ The following ``Ingredient`` class models the documents in the ``ingredients``
613
+ collection:
614
+
615
+ .. code-block:: csharp
616
+
617
+ public class Ingredient {
618
+ public int Id { get; set; }
619
+ public string Name { get; set; }
620
+ public int Price { get; set; }
621
+ public int Count { get; set; }
622
+ }
623
+
624
+ .. note::
625
+
626
+ For all bitwise operators, if the operand list contains a missing or undefined
627
+ value, the entire expression evaluates to ``null``.
628
+
629
+
591
630
$bitAnd
592
- ~~~~~~~
631
+ +++++++
593
632
594
633
The ``$bitAnd`` aggregation stage performs a bitwise AND operation on the given
595
- arguments. ``$bitAnd`` can take // describe arguments
634
+ arguments. The following example shows how to generate a ``$bitAnd`` stage using
635
+ LINQ:
596
636
597
637
.. code-block:: csharp
598
638
599
- var queryable = collection .AsQueryable()
600
- .Select(x => x.P & x.Q
601
- );
639
+ var query = queryableCollection .AsQueryable()
640
+ .Where(i => i.Name == "eggs")
641
+ .Select(x => x.Price & x.Count );
602
642
603
- The result of the preceding example look like this:
643
+ The preceding example finds the document where the ``Name`` field has the value
644
+ ``"eggs"``. It then performs a bitwise AND operation on the values of the
645
+ ``Price`` and ``Count`` fields in this document. The result contains one value:
646
+ ``4``.
647
+
648
+ The following example performs the same bitwise AND operation, but on all
649
+ documents in the collection:
650
+
651
+ .. code-block:: csharp
604
652
605
- // what should the parameters look like?
653
+ var query = queryableCollection.AsQueryable()
654
+ .Select(x => x.Price & x.Count);
606
655
607
- // 2 arguments <-- the example should correspond to the pagewide example
608
- // 3 arguments
656
+ The result of the preceding example contains the following values.
609
657
610
- // restaurants collection
658
+ .. code-block:: json
659
+
660
+ 1
661
+ 0
662
+ 4
663
+ 0
664
+ 4
665
+ null
611
666
667
+ Note that the ``null`` result comes from the document where the ``Name`` field
668
+ has the value of ``"cheese"``. This document is missing a ``Count`` field, so
669
+ the expression evaluates to ``null``.
612
670
613
671
$bitOr
614
672
~~~~~~
615
673
616
674
The ``$bitOr`` aggregation stage performs a bitwise OR operation on the given
617
- arguments. ``$bitOr`` can take // describe arguments - same as AND and XOR
675
+ arguments. The following example shows how to generate a ``$bitOr`` stage using
676
+ LINQ:
618
677
619
678
.. code-block:: csharp
620
679
621
- var queryable = collection .AsQueryable()
622
- .Select(x => x.P | x.Q
623
- );
680
+ var query = queryableCollection .AsQueryable()
681
+ .Where(i => i.Name == "eggs")
682
+ .Select(x => x.Price | x.Count );
624
683
625
- The result of the preceding example look like this:
684
+ The preceding example finds the document where the ``Name`` field has the value
685
+ ``"eggs"``. It then performs a bitwise OR operation on the values of the
686
+ ``Price`` and ``Count`` fields in this document. The result contains one value:
687
+ ``13``.
626
688
627
689
$bitNot
628
690
~~~~~~~
629
691
630
692
The ``$bitNot`` aggregation stage performs a bitwise NOT operation on the given
631
- argument. ``$bitOr `` only takes one argument.
693
+ argument. ``$bitNot `` only takes one argument.
632
694
633
695
.. code-block:: csharp
634
696
635
697
var queryable = collection.AsQueryable()
636
- .Select(x => ! x.P
698
+ .Select(x => ~ x.P
637
699
);
638
700
639
701
The result of the preceding example looks like this:
@@ -645,7 +707,7 @@ The ``$bitXor`` aggregation stage performs a bitwise XOR operation on the given
645
707
arguments. ``$bitXor`` can take // describe arguments - same as AND and XOR
646
708
647
709
.. code-block:: csharp
648
-
710
+
649
711
var queryable = collection.AsQueryable()
650
712
.Select(x => x.P ^ x.Q
651
713
);
0 commit comments