Skip to content

Commit 1af0f8b

Browse files
DOCSP-22866 clustered indexes (#234)
* added clustered indexes
1 parent d6ab577 commit 1af0f8b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

source/fundamentals/indexes.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,30 @@ Refer to the :manual:`Unique Indexes page </core/index-unique>` in the MongoDB s
397397

398398
.. driver-content-end
399399

400+
Clustered Indexes
401+
~~~~~~~~~~~~~~~~~
402+
403+
**Clustered indexes** instruct a collection to store documents ordered
404+
by a key value. To create a clustered index, specify the clustered index
405+
option with the ``_id`` field as the key and the unique field as
406+
``true`` when you create your collection.
407+
408+
The following example creates a clustered index on the ``_id`` field in
409+
the ``vendors`` collection:
410+
411+
.. code-block:: java
412+
413+
MongoDatabase database = mongoClient.getDatabase("tea");
414+
ClusteredIndexOptions clusteredIndexOptions = new ClusteredIndexOptions(new Document("_id", 1), true);
415+
CreateCollectionOptions createCollectionOptions = new CreateCollectionOptions().clusteredIndexOptions(clusteredIndexOptions);
416+
417+
database.createCollection("vendors", createCollectionOptions);
418+
419+
See the MongoDB server manual sections for more information:
420+
421+
- :ref:`Clustered Indexes <db.createCollection.clusteredIndex>`
422+
- :ref:`Clustered Collections <clustered-collections>`
423+
400424
Remove an Index
401425
---------------
402426

0 commit comments

Comments
 (0)