diff --git a/source/indexes.txt b/source/indexes.txt index 62c52fe1..dbc2f98c 100644 --- a/source/indexes.txt +++ b/source/indexes.txt @@ -1,8 +1,8 @@ .. _csharp-indexes: -======= -Indexes -======= +========================= +Create and Manage Indexes +========================= .. facet:: :name: genre @@ -70,7 +70,18 @@ Index Types ----------- MongoDB provides several different index types to support querying -your data. The following sections describe the most common index types +your data. The following steps describe the process for creating an index: + +1. Use the ``IndexKeysDefinitionBuilder`` class, which you can access through the + ``Builders.IndexKeys`` property, to create one or more + ``IndexKeysDefinition`` objects. These key definitions describe the type + of index to create and the index's other properties. +#. Create a new ``CreateIndexModel`` object. Pass the key definitions from the + previous step to the constructor. +#. Call the ``CreateOne()`` method on your collection's ``Indexes`` property. Pass + the ``CreateIndexModel`` object from the previous step. + +The following sections describe the most common index types and provide sample code for creating each index type. .. note:: @@ -313,9 +324,15 @@ and :manual:`Text Indexes ` in the Server manual. Geospatial Indexes ~~~~~~~~~~~~~~~~~~ -MongoDB supports queries of geospatial coordinate data using **2dsphere -indexes**. With a 2dsphere index, you can query the geospatial data for -inclusion, intersection, and proximity. +You can query geospatial coordinate data in MongoDB by using **2d** or +**2dsphere indexes**. + +2dsphere Indexes +++++++++++++++++ + +2dsphere indexes support geospatial queries on an earth-like sphere. By using a 2dsphere +index, you can query the geospatial data For inclusion, intersection, and proximity. +The indexed field must be either GeoJSON objects or legacy coordinate pairs. To create a 2dsphere index, you must specify a field that contains only **GeoJSON objects**. For more details about this type, see :manual:`GeoJSON objects ` @@ -367,7 +384,11 @@ The following is an example of a geospatial query using the "location.geo" index :end-before: end-geospatial-query :dedent: -MongoDB also supports ``2d`` indexes for calculating distances on a Euclidean plane and +2d Indexes +++++++++++ + +The {+driver-short+} also includes a ``Geo2D`` method for creating 2d indexes. +You can use these indexes to calculate distances on a Euclidean plane and for working with the "legacy coordinate pairs" syntax used in MongoDB 2.2 and earlier. To learn more, see :manual:`Geospatial Queries ` in the Server manual. @@ -433,81 +454,12 @@ all indexes in a collection: :end-before: end-list-indexes :dedent: -.. TODO: integrate into existing page - -Sample Class ------------- - -The code examples in this guide demonstrate how you can use builders to -create types to interact with documents in the sample collection ``plants.flowers``. -Documents in this collection are modeled by the following ``Flower`` class: - -.. literalinclude:: /includes/fundamentals/code-examples/builders.cs - :language: csharp - :dedent: - :start-after: start-model - :end-before: end-model - -Each builder class takes a generic type parameter -``TDocument`` which represents the type of document that you are working -with. In this guide, the ``Flower`` class is the document type used in -each builder class example. - -.. _csharp-builders-indexes: - -Define Index Keys ------------------ - -The ``IndexKeysDefinitionBuilder`` class provides a type-safe interface for -defining index keys. Suppose you want to select ``Category`` as an -ascending index key. - -Use builders to select the index key with the typed variant: - -.. code-block:: csharp - :copyable: true - - var builder = Builders.IndexKeys; - var keys = builder.Ascending(f => f.Category); - -Alternatively, you can use string-based field names to select the index key: - -.. code-block:: csharp - :copyable: true - - var builder = Builders.IndexKeys; - var keys = builder.Ascending("Category"); - -The ``IndexKeysDefinitionBuilder`` class also provides methods to build -a wildcard index. You can create a wildcard index using ``All field paths`` or ``A -single field path``, in this case using ``Category``: - -.. tabs:: - - .. tab:: ``All field paths`` - :tabid: all-wildcard-index - - .. code-block:: csharp - :copyable: true - - var builder = Builders.IndexKeys; - var keys = builder.Wildcard(); - - .. tab:: ``A single field path`` - :tabid: single-wildcard-index - - .. code-block:: csharp - :copyable: true - - var builder = Builders.IndexKeys; - - // Using the typed variant - var keys = builder.Wildcard(f => f.Category); - - // Using string-based field names - var keys = builder.Wildcard("Category"); +Additional Information +---------------------- -For more information about how to use wildcard indexes, see -:manual:`Wildcard Indexes `. +For more information about the classes and methods used on this page, see the following +API documentation: +- `CreateOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoIndexManager-1.CreateOne.html>`__ +- `CreateIndexModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CreateIndexModel-1.html>`__ - `IndexKeysDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IndexKeysDefinitionBuilder-1.html>`__ \ No newline at end of file diff --git a/source/reference/quick-reference.txt b/source/reference/quick-reference.txt index 8b03bd9e..3e81573a 100644 --- a/source/reference/quick-reference.txt +++ b/source/reference/quick-reference.txt @@ -561,7 +561,7 @@ their related reference and API documentation. * - | **Create an Index** | | `API Documentation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoIndexManager-1.CreateOne.html>`__ - | :ref:`Fundamentals ` + | :ref:`Fundamentals ` - .. code-block:: csharp :copyable: true