Skip to content

Commit c1a64dd

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-20349 add example to create indexes (#878)
* DOCSP-20349-add-example-to-createIndexes * DOCSP-20349-add-example-to-createIndexes * DOCSP-20349-add-example-to-createIndexes Co-authored-by: jason-price-mongodb <[email protected]>
1 parent df565d6 commit c1a64dd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

source/reference/method/db.collection.createIndexes.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,29 @@ majority of data-bearing voting members "vote" to commit the index
10321032
build. For more information on index builds and the voting process, see
10331033
:ref:`index-operations-replicated-build`.
10341034

1035+
Create Multiple Indexes
1036+
~~~~~~~~~~~~~~~~~~~~~~~
1037+
1038+
.. include:: /includes/cakeSales-example-collection.rst
1039+
1040+
The following example creates multiple indexes on the ``cakeSales``
1041+
collection:
1042+
1043+
.. code-block:: javascript
1044+
1045+
db.cakeSales.createIndexes( [
1046+
{ "type": 1 },
1047+
{ "orderDate": 1 },
1048+
{ "state": 1 },
1049+
{ "orderDate": 1, "state": -1 }
1050+
] )
1051+
1052+
The first three indexes are on single fields and in ascending order
1053+
(``1``).
1054+
1055+
The last index is on ``orderDate`` in ascending order (``1``) and
1056+
``state`` in descending order (``-1``).
1057+
10351058
Additional Information
10361059
----------------------
10371060

0 commit comments

Comments
 (0)