Skip to content

Commit 137151e

Browse files
authored
DOCSP-49082 - Indexes (Comprehensive Coverage) (#623)
1 parent 4a6a5bc commit 137151e

File tree

2 files changed

+36
-84
lines changed

2 files changed

+36
-84
lines changed

source/indexes.txt

+35-83
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _csharp-indexes:
22

3-
=======
4-
Indexes
5-
=======
3+
=========================
4+
Create and Manage Indexes
5+
=========================
66

77
.. facet::
88
:name: genre
@@ -70,7 +70,18 @@ Index Types
7070
-----------
7171

7272
MongoDB provides several different index types to support querying
73-
your data. The following sections describe the most common index types
73+
your data. The following steps describe the process for creating an index:
74+
75+
1. Use the ``IndexKeysDefinitionBuilder<TDocument>`` class, which you can access through the
76+
``Builders<TDocument>.IndexKeys`` property, to create one or more
77+
``IndexKeysDefinition<TDocument>`` objects. These key definitions describe the type
78+
of index to create and the index's other properties.
79+
#. Create a new ``CreateIndexModel<TDocument>`` object. Pass the key definitions from the
80+
previous step to the constructor.
81+
#. Call the ``CreateOne()`` method on your collection's ``Indexes`` property. Pass
82+
the ``CreateIndexModel<TDocument>`` object from the previous step.
83+
84+
The following sections describe the most common index types
7485
and provide sample code for creating each index type.
7586

7687
.. note::
@@ -313,9 +324,15 @@ and :manual:`Text Indexes </core/index-text>` in the Server manual.
313324
Geospatial Indexes
314325
~~~~~~~~~~~~~~~~~~
315326

316-
MongoDB supports queries of geospatial coordinate data using **2dsphere
317-
indexes**. With a 2dsphere index, you can query the geospatial data for
318-
inclusion, intersection, and proximity.
327+
You can query geospatial coordinate data in MongoDB by using **2d** or
328+
**2dsphere indexes**.
329+
330+
2dsphere Indexes
331+
++++++++++++++++
332+
333+
2dsphere indexes support geospatial queries on an earth-like sphere. By using a 2dsphere
334+
index, you can query the geospatial data For inclusion, intersection, and proximity.
335+
The indexed field must be either GeoJSON objects or legacy coordinate pairs.
319336

320337
To create a 2dsphere index, you must specify a field that contains
321338
only **GeoJSON objects**. For more details about this type, see :manual:`GeoJSON objects </reference/geojson>`
@@ -367,7 +384,11 @@ The following is an example of a geospatial query using the "location.geo" index
367384
:end-before: end-geospatial-query
368385
:dedent:
369386

370-
MongoDB also supports ``2d`` indexes for calculating distances on a Euclidean plane and
387+
2d Indexes
388+
++++++++++
389+
390+
The {+driver-short+} also includes a ``Geo2D`` method for creating 2d indexes.
391+
You can use these indexes to calculate distances on a Euclidean plane and
371392
for working with the "legacy coordinate pairs" syntax used in MongoDB 2.2 and earlier.
372393
To learn more, see :manual:`Geospatial Queries </geospatial-queries>` in the Server manual.
373394

@@ -433,81 +454,12 @@ all indexes in a collection:
433454
:end-before: end-list-indexes
434455
:dedent:
435456

436-
.. TODO: integrate into existing page
437-
438-
Sample Class
439-
------------
440-
441-
The code examples in this guide demonstrate how you can use builders to
442-
create types to interact with documents in the sample collection ``plants.flowers``.
443-
Documents in this collection are modeled by the following ``Flower`` class:
444-
445-
.. literalinclude:: /includes/fundamentals/code-examples/builders.cs
446-
:language: csharp
447-
:dedent:
448-
:start-after: start-model
449-
:end-before: end-model
450-
451-
Each builder class takes a generic type parameter
452-
``TDocument`` which represents the type of document that you are working
453-
with. In this guide, the ``Flower`` class is the document type used in
454-
each builder class example.
455-
456-
.. _csharp-builders-indexes:
457-
458-
Define Index Keys
459-
-----------------
460-
461-
The ``IndexKeysDefinitionBuilder`` class provides a type-safe interface for
462-
defining index keys. Suppose you want to select ``Category`` as an
463-
ascending index key.
464-
465-
Use builders to select the index key with the typed variant:
466-
467-
.. code-block:: csharp
468-
:copyable: true
469-
470-
var builder = Builders<Flower>.IndexKeys;
471-
var keys = builder.Ascending(f => f.Category);
472-
473-
Alternatively, you can use string-based field names to select the index key:
474-
475-
.. code-block:: csharp
476-
:copyable: true
477-
478-
var builder = Builders<BsonDocument>.IndexKeys;
479-
var keys = builder.Ascending("Category");
480-
481-
The ``IndexKeysDefinitionBuilder`` class also provides methods to build
482-
a wildcard index. You can create a wildcard index using ``All field paths`` or ``A
483-
single field path``, in this case using ``Category``:
484-
485-
.. tabs::
486-
487-
.. tab:: ``All field paths``
488-
:tabid: all-wildcard-index
489-
490-
.. code-block:: csharp
491-
:copyable: true
492-
493-
var builder = Builders<Flower>.IndexKeys;
494-
var keys = builder.Wildcard();
495-
496-
.. tab:: ``A single field path``
497-
:tabid: single-wildcard-index
498-
499-
.. code-block:: csharp
500-
:copyable: true
501-
502-
var builder = Builders<Flower>.IndexKeys;
503-
504-
// Using the typed variant
505-
var keys = builder.Wildcard(f => f.Category);
506-
507-
// Using string-based field names
508-
var keys = builder.Wildcard("Category");
457+
Additional Information
458+
----------------------
509459

510-
For more information about how to use wildcard indexes, see
511-
:manual:`Wildcard Indexes </core/indexes/index-types/index-wildcard>`.
460+
For more information about the classes and methods used on this page, see the following
461+
API documentation:
512462

463+
- `CreateOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoIndexManager-1.CreateOne.html>`__
464+
- `CreateIndexModel<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CreateIndexModel-1.html>`__
513465
- `IndexKeysDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IndexKeysDefinitionBuilder-1.html>`__

source/reference/quick-reference.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ their related reference and API documentation.
561561
* - | **Create an Index**
562562
|
563563
| `API Documentation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoIndexManager-1.CreateOne.html>`__
564-
| :ref:`Fundamentals <csharp-builders-indexes>`
564+
| :ref:`Fundamentals <csharp-indexes>`
565565

566566
- .. code-block:: csharp
567567
:copyable: true

0 commit comments

Comments
 (0)