Skip to content

Commit 9be6627

Browse files
author
Sam Kleinman
committed
DOCS-902 adding notes about $or operator and 2d geo queries
1 parent 1f28a8a commit 9be6627

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

source/reference/limits.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Indexes
9393
.. see:: :doc:`/tutorial/enforce-unique-keys-for-sharded-collections`
9494
for an alternate approach.
9595

96-
.. limit:: Number of Indexed Fields in a Compound Index:
96+
.. limit:: Number of Indexed Fields in a Compound Index
9797

9898
There can be no more than 31 fields in a compound index.
9999

@@ -137,6 +137,10 @@ Operations
137137

138138
:operator:`$snapshot` queries do not work in sharded environments.
139139

140+
.. limit:: 2d Geospatial queries cannot use the $or operator
141+
142+
.. see:: :operator:`$or` and :doc:`/core/geospatial-indexes`.
143+
140144
Naming Restrictions
141145
~~~~~~~~~~~~~~~~~~~
142146

@@ -178,12 +182,10 @@ Naming Restrictions
178182
See :ref:`faq-restrictions-on-collection-names` and
179183
:ref:`rn-2.2-collection-name-restriction` for more information.
180184

181-
.. _limit-restrictions-on-field-names:
185+
.. _limit-restrictions-on-field-names:
182186

183187
.. limit:: Restrictions on Field Names
184188

185189
Field names cannot contain dots (i.e. ``.``), dollar signs
186190
(i.e. ``$``), or null characters. See
187191
:ref:`faq-dollar-sign-escaping` for an alternate approach.
188-
189-

source/reference/operator/or.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,54 @@ $or
1919
*at least* one of the ``<expressions>``.
2020

2121
Consider the following query:
22-
22+
2323
.. code-block:: javascript
24-
24+
2525
db.inventory.find( { price:1.99, $or: [ { qty: { $lt: 20 } }, { sale: true } ] } )
26-
26+
2727
This query will select all documents in the ``inventory`` collection
2828
where:
29-
30-
- the ``price`` field value equals ``1.99`` *and*
29+
30+
- the ``price`` field value equals ``1.99`` *and*
3131
- either the ``qty`` field value is less than ``20`` **or** the
3232
``sale`` field value is ``true``.
33-
33+
3434
Consider the following example which uses the :operator:`$or` operator to select
3535
fields from embedded documents:
3636

3737
.. code-block:: javascript
38-
38+
3939
db.inventory.update( { $or: [ { price:10.99 }, { "carrier.state": "NY"} ] }, { $set: { sale: true } } )
40-
40+
4141
This :method:`update() <db.collection.update()>` operation will set
4242
the value of the ``sale`` field in the documents in the
4343
``inventory`` collection where:
44-
45-
- the ``price`` field value equals ``10.99`` **or**
44+
45+
- the ``price`` field value equals ``10.99`` **or**
4646
- the ``carrier`` embedded document contains a field ``state`` whose
4747
value equals ``NY``.
48-
48+
4949
When using :operator:`$or` with ``<expressions>`` that are equality
5050
checks for the value of the same field, choose the :operator:`$in`
5151
operator over the :operator:`$or` operator.
52-
52+
5353
Consider the query to select all documents in the ``inventory``
5454
collection where:
55-
55+
5656
- either ``price`` field value equals ``1.99`` *or* the ``sale``
5757
field value equals ``true``, **and**
5858
- either ``qty`` field value equals ``20`` *or* ``qty`` field value
5959
equals ``50``,
60-
60+
6161
The most effective query would be:
62-
62+
6363
.. code-block:: javascript
64-
64+
6565
db.inventory.find ( { $or: [ { price: 1.99 }, { sale: true } ], qty: { $in: [20, 50] } } )
6666

6767
Consider the following behaviors when using the :operator:`$or`
6868
operator:
69-
69+
7070
- When using indexes with :operator:`$or` queries, remember that
7171
each clause of an :operator:`$or` query will execute in parallel.
7272
These clauses can each use their own index. Consider the following
@@ -93,6 +93,9 @@ $or
9393
This modified query will not use the index on ``price`` nor the
9494
index on ``sale``.
9595

96+
- You cannot use the :operator:`$or` with ``2d`` :doc:`geospatial
97+
queries </core/geospatial-indexes>`.
98+
9699
.. seealso:: :method:`find() <db.collection.find()>`,
97100
:method:`update() <db.collection.update()>`, :operator:`$set`,
98101
:operator:`$and`, :method:`sort() <cursor.sort()>`.

0 commit comments

Comments
 (0)