@@ -200,8 +200,9 @@ A simple selector, inspecting specific fields:
200
200
201
201
You can create more complex selector expressions by combining operators.
202
202
For best performance, it is best to combine 'combination' or
203
- 'array logical' operators, such as ``$regex ``, with an equality
204
- operators such as ``$eq ``, ``$gt ``, ``$gte ``, ``$lt ``, and ``$lte ``
203
+ 'array logical' operators, such as ``$regex ``, with an operator
204
+ that defines a contiguous range of keys such as ``$eq ``,
205
+ ``$gt ``, ``$gte ``, ``$lt ``, ``$lte ``, and ``$beginsWith ``
205
206
(but not ``$ne ``). For more information about creating complex
206
207
selector expressions, see :ref: `creating selector expressions
207
208
<find/expressions>`.
@@ -673,68 +674,74 @@ In addition, some 'meta' condition operators are available. Some condition
673
674
operators accept any valid JSON content as the argument. Other condition
674
675
operators require the argument to be in a specific JSON format.
675
676
676
- +---------------+-------------+------------+-----------------------------------+
677
- | Operator type | Operator | Argument | Purpose |
678
- +===============+=============+============+===================================+
679
- | (In)equality | ``$lt `` | Any JSON | The field is less than the |
680
- | | | | argument. |
681
- +---------------+-------------+------------+-----------------------------------+
682
- | | ``$lte `` | Any JSON | The field is less than or equal to|
683
- | | | | the argument. |
684
- +---------------+-------------+------------+-----------------------------------+
685
- | | ``$eq `` | Any JSON | The field is equal to the argument|
686
- +---------------+-------------+------------+-----------------------------------+
687
- | | ``$ne `` | Any JSON | The field is not equal to the |
688
- | | | | argument. |
689
- +---------------+-------------+------------+-----------------------------------+
690
- | | ``$gte `` | Any JSON | The field is greater than or equal|
691
- | | | | to the argument. |
692
- +---------------+-------------+------------+-----------------------------------+
693
- | | ``$gt `` | Any JSON | The field is greater than the |
694
- | | | | to the argument. |
695
- +---------------+-------------+------------+-----------------------------------+
696
- | Object | ``$exists `` | Boolean | Check whether the field exists or |
697
- | | | | not, regardless of its value. |
698
- +---------------+-------------+------------+-----------------------------------+
699
- | | ``$type `` | String | Check the document field's type. |
700
- | | | | Valid values are ``"null" ``, |
701
- | | | | ``"boolean" ``, ``"number" ``, |
702
- | | | | ``"string" ``, ``"array" ``, and |
703
- | | | | ``"object" ``. |
704
- +---------------+-------------+------------+-----------------------------------+
705
- | Array | ``$in `` | Array of | The document field must exist in |
706
- | | | JSON values| the list provided. |
707
- +---------------+-------------+------------+-----------------------------------+
708
- | | ``$nin `` | Array of | The document field not must exist |
709
- | | | JSON values| in the list provided. |
710
- +---------------+-------------+------------+-----------------------------------+
711
- | | ``$size `` | Integer | Special condition to match the |
712
- | | | | length of an array field in a |
713
- | | | | document. Non-array fields cannot |
714
- | | | | match this condition. |
715
- +---------------+-------------+------------+-----------------------------------+
716
- | Miscellaneous | ``$mod `` | [Divisor, | Divisor is a non-zero integer, |
717
- | | | Remainder] | Remainder is any integer. |
718
- | | | | Non-integer values result in a |
719
- | | | | 404. Matches documents where |
720
- | | | | ``field % Divisor == Remainder `` |
721
- | | | | is true, and only when the |
722
- | | | | document field is an integer. |
723
- +---------------+-------------+------------+-----------------------------------+
724
- | | ``$regex `` | String | A regular expression pattern to |
725
- | | | | match against the document field. |
726
- | | | | Only matches when the field is a |
727
- | | | | string value and matches the |
728
- | | | | supplied regular expression. The |
729
- | | | | matching algorithms are based on |
730
- | | | | the Perl Compatible Regular |
731
- | | | | Expression (PCRE) library. For |
732
- | | | | more information about what is |
733
- | | | | implemented, see the see the |
734
- | | | | `Erlang Regular Expression |
735
- | | | | <http://erlang.org/doc |
736
- | | | | /man/re.html>`_. |
737
- +---------------+-------------+------------+-----------------------------------+
677
+ +---------------+-----------------+-------------+------------------------------------+
678
+ | Operator type | Operator | Argument | Purpose |
679
+ +===============+=================+=============+====================================+
680
+ | (In)equality | ``$lt `` | Any JSON | The field is less than the |
681
+ | | | | argument. |
682
+ +---------------+-----------------+-------------+------------------------------------+
683
+ | | ``$lte `` | Any JSON | The field is less than or equal to |
684
+ | | | | the argument. |
685
+ +---------------+-----------------+-------------+------------------------------------+
686
+ | | ``$eq `` | Any JSON | The field is equal to the argument |
687
+ +---------------+-----------------+-------------+------------------------------------+
688
+ | | ``$ne `` | Any JSON | The field is not equal to the |
689
+ | | | | argument. |
690
+ +---------------+-----------------+-------------+------------------------------------+
691
+ | | ``$gte `` | Any JSON | The field is greater than or equal |
692
+ | | | | to the argument. |
693
+ +---------------+-----------------+-------------+------------------------------------+
694
+ | | ``$gt `` | Any JSON | The field is greater than the |
695
+ | | | | to the argument. |
696
+ +---------------+-----------------+-------------+------------------------------------+
697
+ | Object | ``$exists `` | Boolean | Check whether the field exists or |
698
+ | | | | not, regardless of its value. |
699
+ +---------------+-----------------+-------------+------------------------------------+
700
+ | | ``$type `` | String | Check the document field's type. |
701
+ | | | | Valid values are ``"null" ``, |
702
+ | | | | ``"boolean" ``, ``"number" ``, |
703
+ | | | | ``"string" ``, ``"array" ``, and |
704
+ | | | | ``"object" ``. |
705
+ +---------------+-----------------+-------------+------------------------------------+
706
+ | Array | ``$in `` | Array of | The document field must exist in |
707
+ | | | JSON values | the list provided. |
708
+ +---------------+-----------------+-------------+------------------------------------+
709
+ | | ``$nin `` | Array of | The document field not must exist |
710
+ | | | JSON values | in the list provided. |
711
+ +---------------+-----------------+-------------+------------------------------------+
712
+ | | ``$size `` | Integer | Special condition to match the |
713
+ | | | | length of an array field in a |
714
+ | | | | document. Non-array fields cannot |
715
+ | | | | match this condition. |
716
+ +---------------+-----------------+-------------+------------------------------------+
717
+ | Miscellaneous | ``$mod `` | [Divisor, | Divisor is a non-zero integer, |
718
+ | | | Remainder] | Remainder is any integer. |
719
+ | | | | Non-integer values result in a |
720
+ | | | | 404. Matches documents where |
721
+ | | | | ``field % Divisor == Remainder `` |
722
+ | | | | is true, and only when the |
723
+ | | | | document field is an integer. |
724
+ +---------------+-----------------+-------------+------------------------------------+
725
+ | | ``$regex `` | String | A regular expression pattern to |
726
+ | | | | match against the document field. |
727
+ | | | | Only matches when the field is a |
728
+ | | | | string value and matches the |
729
+ | | | | supplied regular expression. The |
730
+ | | | | matching algorithms are based on |
731
+ | | | | the Perl Compatible Regular |
732
+ | | | | Expression (PCRE) library. For |
733
+ | | | | more information about what is |
734
+ | | | | implemented, see the see the |
735
+ | | | | `Erlang Regular Expression |
736
+ | | | | <http://erlang.org/doc |
737
+ | | | | /man/re.html>`_. |
738
+ +---------------+-----------------+-------------+------------------------------------+
739
+ | | ``$beginsWith `` | String | Matches where the document field |
740
+ | | | | begins with the specified prefix |
741
+ | | | | (case-sensitive). If the document |
742
+ | | | | field contains a non-string value, |
743
+ | | | | the document is not matched. |
744
+ +---------------+-----------------+-------------+------------------------------------+
738
745
739
746
.. warning ::
740
747
Regular expressions do not work with indexes, so they should not be used to
@@ -753,9 +760,12 @@ In general, whenever you have an operator that takes an argument, that argument
753
760
can itself be another operator with arguments of its own. This enables us to
754
761
build up more complex selector expressions.
755
762
756
- However, only equality operators such as ``$eq ``, ``$gt ``, ``$gte ``, ``$lt ``,
757
- and ``$lte `` (but not ``$ne ``) can be used as the basis of a query. You should
758
- include at least one of these in a selector.
763
+ However, only operators that define a contiguous range of values
764
+ such as ``$eq ``, ``$gt ``, ``$gte ``, ``$lt ``, ``$lte ``,
765
+ and ``$beginsWith `` (but not ``$ne ``) can be used as the basis
766
+ of a query that can make efficient use of a ``json `` index. You should
767
+ include at least one of these in a selector, or consider using
768
+ a ``text `` index if greater flexibility is required.
759
769
760
770
For example, if you try to perform a query that attempts to match all documents
761
771
that have a field called `afieldname ` containing a value that begins with the
0 commit comments