Skip to content

Commit f23c162

Browse files
(DOCSP-11197): Wildcard index clarifications (#280)
* (DOCSP-11197): Wildcard index clarifications * copy review edits * updates per review
1 parent c229b66 commit f23c162

File tree

2 files changed

+89
-19
lines changed

2 files changed

+89
-19
lines changed
Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
11
title: Click the :guilabel:`Create Index` button.
22
level: 4
33
ref: create-collection
4+
stepnum: 1
45
content: |
5-
From the :ref:`Indexes <collection-tab>` tab, click the
6-
:guilabel:`Create Index` button to bring up the
6+
From the :ref:`Indexes <collection-tab>` tab, click
7+
:guilabel:`Create Index` to open the
78
:guilabel:`Create Index` dialog.
89
---
910
title: Optional. Enter the index name.
1011
level: 4
1112
ref: enter-index-name
13+
stepnum: 2
1214
content: |
1315
In the dialog, enter the name of the index to create, or leave blank
1416
to have MongoDB create a default name for the index.
1517
---
1618
title: Add fields to index.
1719
level: 4
1820
ref: index-fields
21+
stepnum: 3
1922
content: |
20-
To specify a key for the index, select the field and the index type.
21-
To index additional fields, click :guilabel:`Add Another Field`.
23+
24+
a. Specify an index key.
25+
26+
- To specify an existing document field as an index key, select
27+
the field from the dropdown list.
28+
29+
- To specify a field which does not exist in any document as an
30+
index key, enter the field name in the input box.
31+
32+
- To create a :manual:`compound index </core/index-compound/>`,
33+
click :guilabel:`Add Another Field`.
34+
35+
b. Use the dropdown to the right of each field name to specify the
36+
index type (``ascending``, ``descending``, or
37+
:manual:`2dsphere </core/2dsphere/>`).
38+
39+
.. seealso::
40+
41+
To learn how to specify a wildcard index, see
42+
:ref:`compass-wildcard-index`.
43+
2244
---
2345
title: Optional. Specify the index options.
2446
level: 4
2547
ref: index-options
48+
stepnum: 4
2649
content: |
2750
2851
|compass-short| supports the following index options:
@@ -37,29 +60,28 @@ content: |
3760
3861
* - Build index in the background
3962
40-
- If checked, ensure that the MongoDB deployment remains
41-
available during the index build operation.
63+
- Ensure that the MongoDB deployment remains available during
64+
the index build operation.
4265
4366
- :manual:`Background Construction </core/index-creation/index.html#background-construction>`
4467
4568
* - Create unique index
4669
47-
- If checked, ensure that the indexed fields do not
48-
store duplicate values.
70+
- Ensure that the indexed fields do not store duplicate values.
4971
5072
- :manual:`Unique Indexes </core/index-unique>`
5173
52-
* - Create :abbr:`TTL (Time to Live)`
74+
* - Create a :abbr:`TTL (Time to Live)` index
5375
54-
- If checked, automatically delete documents after a
55-
specified number of seconds since the indexed field value.
76+
- Delete documents automatically after a specified number of
77+
seconds since the indexed field value.
5678
5779
- :manual:`TTL Indexes </core/index-ttl>`
5880
5981
* - Partial filter expression
6082
61-
- If checked, only index documents which match the specified
62-
filter expression.
83+
- Index only the documents which match the specified filter
84+
expression.
6385
6486
.. example::
6587
@@ -74,20 +96,38 @@ content: |
7496
7597
* - Use custom collation
7698
77-
- If checked, create a custom collation for the index
78-
using the options provided in |compass-short|.
99+
- Create a custom collation for the index using the options
100+
provided in |compass-short|.
79101
80102
- :manual:`Collation Document </reference/collation/#collation-document>`
81103
82104
* - Wildcard projection (*New in MongoDB 4.2*)
83105
84-
- If checked, support unknown or arbitrary fields
85-
which match the specified projection in the index.
106+
- Support unknown or arbitrary fields which match the specified
107+
projection in the index. To use a wildcard projection, set
108+
your index field name to ``$**``. This directs
109+
|compass-short| to use all fields in the document (excluding
110+
``_id``).
111+
112+
.. example::
113+
114+
Consider the following wildcard projection document:
115+
116+
.. code-block:: javascript
117+
118+
{
119+
"product_attributes.elements" : 1,
120+
"product_attributes.resistance" : 1
121+
}
122+
123+
If your index field name is ``$**``, your index only
124+
includes the values of the fields in that projection.
86125
87-
- :manual-next:`Wildcard Indexes </core/index-wildcard/>`
126+
- :ref:`compass-wildcard-index`
88127
---
89-
title: Click :guilabel:`Create` to create the index.
128+
title: Click :guilabel:`Create Index`.
90129
level: 4
91130
ref: create-index-button
131+
stepnum: 5
92132
content: ""
93133
...

source/indexes.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,36 @@ contain documents.
8383

8484
.. include:: /includes/steps/create-index.rst
8585

86+
.. _compass-wildcard-index:
87+
88+
Wildcard Indexes
89+
~~~~~~~~~~~~~~~~
90+
91+
.. versionadded:: v4.2
92+
93+
You can create :manual:`wildcard indexes </core/index-wildcard/>` to
94+
support queries against unknown or arbitrary fields.
95+
96+
.. example::
97+
98+
Consider a collection where documents contain a ``userMetadata``
99+
object. The fields within the ``userMetadata`` object may vary
100+
between documents.
101+
102+
You can create a wildcard index on ``userMetadata`` to account for
103+
all potential fields within the object. In |compass-short|, enter
104+
the following for the index name:
105+
106+
.. code-block:: javascript
107+
108+
userMetadata.$**
109+
110+
Specify a type (``ascending`` or ``descending``) for your wildcard
111+
index, then click :guilabel:`Create Index`.
112+
113+
|compass-short| shows the type of your new index as
114+
:guilabel:`Wildcard`.
115+
86116
.. _drop-index:
87117

88118
Drop an Index

0 commit comments

Comments
 (0)