From 31cfaa9cb7a51a9905175dd8804b0cfa01c56dc0 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 29 Apr 2025 14:02:12 -0500 Subject: [PATCH 1/4] first draft --- source/indexes.txt | 112 +++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 80 deletions(-) diff --git a/source/indexes.txt b/source/indexes.txt index 62c52fe1..909c7f52 100644 --- a/source/indexes.txt +++ b/source/indexes.txt @@ -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: + +- Use the ``IndexKeysDefinitionBuilder`` class, accessible 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 From 09c1c9282f4f54a64a4cd5056b3970d45c7d8ab8 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 29 Apr 2025 14:28:11 -0500 Subject: [PATCH 2/4] title length --- source/indexes.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/indexes.txt b/source/indexes.txt index 909c7f52..9a423a1c 100644 --- a/source/indexes.txt +++ b/source/indexes.txt @@ -1,8 +1,8 @@ .. _csharp-indexes: -======= -Indexes -======= +========================= +Create and Manage Indexes +========================= .. facet:: :name: genre From ebf33aadf0491866ce77cd3efcafd37782d2f029 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 29 Apr 2025 14:52:01 -0500 Subject: [PATCH 3/4] fix broken link --- source/reference/quick-reference.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e2069c88632d7f928e297dd382032e2e4b51ab78 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 30 Apr 2025 09:38:15 -0500 Subject: [PATCH 4/4] rr feedback --- source/indexes.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/indexes.txt b/source/indexes.txt index 9a423a1c..dbc2f98c 100644 --- a/source/indexes.txt +++ b/source/indexes.txt @@ -72,14 +72,14 @@ Index Types MongoDB provides several different index types to support querying your data. The following steps describe the process for creating an index: -- Use the ``IndexKeysDefinitionBuilder`` class, accessible 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. +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.