From fc45962feb039a0322a6aecf79e706dc33c691bd Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:44:01 -0600 Subject: [PATCH 01/20] add files --- .github/pull_request_template.md | 17 ++++++++ .github/workflows/add-netlify-links.yml | 58 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/add-netlify-links.yml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..0334545d --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,17 @@ +# Pull Request Info + +[PR Reviewing Guidelines](https://github.com/mongodb/docs-golang/blob/master/REVIEWING.md) + +JIRA - + +### Staging Links + + + +## Self-Review Checklist + +- [ ] Is this free of any warnings or errors in the RST? +- [ ] Did you run a spell-check? +- [ ] Did you run a grammar-check? +- [ ] Are all the links working? +- [ ] Are the [facets and meta keywords](https://wiki.corp.mongodb.com/display/DE/Docs+Taxonomy) accurate? diff --git a/.github/workflows/add-netlify-links.yml b/.github/workflows/add-netlify-links.yml new file mode 100644 index 00000000..08b0391b --- /dev/null +++ b/.github/workflows/add-netlify-links.yml @@ -0,0 +1,58 @@ +name: Add Netlify Links To Changed Pages +on: + workflow_call: + pull_request_target: +jobs: + get-pr-changes: + name: Get Changed Files & Update PR Description + runs-on: ubuntu-latest + permissions: + issues: write + contents: write + pull-requests: write + repository-projects: write + steps: + - uses: actions/checkout@v4 + - name: Get Changed Files + id: changed-files + # pin to a specific commit to ensure stability + uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c + with: + separator: "," + files: source/** + - name: Build Netlify Links for Changed Pages + id: build_page_links + env: + CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + new_links="" + base_link='https://deploy-preview-${{ github.event.number }}--mongodb-docs-ruby.netlify.app' + files=$(echo "$CHANGED_FILES" | tr "," "\n") + for file in $files; do + echo "processing ${file}" + if (! grep -s "includes/" <<< "$file") && + (! grep -s "images/" <<< "$file") && + (! grep -s "examples/" <<< "$file"); then + file="${file#source}" + file="${file%.txt}" + filenoslash="${file:1}" + echo "${base_link}${file}" + new_links+="
  • ${filenoslash}
  • " + else + echo "(file skipped)" + fi + done + if [ "$new_links" == "" ]; then + new_links="No pages to preview" + fi + echo "Final new_links string: " + echo "${new_links}" + echo "staging_links=${new_links}" >> "$GITHUB_OUTPUT" + - name: Update the PR Description + uses: MongoCaleb/pr-description-action@master + with: + regex: ".*" + appendContentOnMatchOnly: true + regexFlags: is + content: "\n${{ steps.build_page_links.outputs.staging_links }}\n" + token: ${{ secrets.GITHUB_TOKEN }} From c2b53c0748f725fdb23025ab0afcee3b56d90017 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:26:01 -0600 Subject: [PATCH 02/20] Update add-netlify-links.yml (#90) --- .github/workflows/add-netlify-links.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-netlify-links.yml b/.github/workflows/add-netlify-links.yml index 08b0391b..fc228e4f 100644 --- a/.github/workflows/add-netlify-links.yml +++ b/.github/workflows/add-netlify-links.yml @@ -26,7 +26,7 @@ jobs: CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} run: | new_links="" - base_link='https://deploy-preview-${{ github.event.number }}--mongodb-docs-ruby.netlify.app' + base_link='https://deploy-preview-${{ github.event.number }}--docs-ruby.netlify.app' files=$(echo "$CHANGED_FILES" | tr "," "\n") for file in $files; do echo "processing ${file}" From b41483b4a3180337a7a5d00361e0f5012478504a Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 09:24:33 -0500 Subject: [PATCH 03/20] DOCSP-45076: Document that count supports different filters from countDocuments --- snooty.toml | 1 + source/reference/aggregation.txt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/snooty.toml b/snooty.toml index d1765ce7..38b23928 100644 --- a/snooty.toml +++ b/snooty.toml @@ -2,3 +2,4 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] +mdb-server = "MongoDB Server" \ No newline at end of file diff --git a/source/reference/aggregation.txt b/source/reference/aggregation.txt index f9e63f99..a75bbaac 100644 --- a/source/reference/aggregation.txt +++ b/source/reference/aggregation.txt @@ -98,6 +98,14 @@ find the total number of documents which have the exact array count = coll.count({ 'categories' => [ 'Chinese', 'Seafood' ] }) +.. note:: + + The ``count`` method is not the same as the ``countDocuments`` + method and may not support the same filters. ``countDocuments`` uses the + ``$match`` stage of the aggregation pipeline to filter documents. To learn more + about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` + in the {+mdb-server+} documentation. + Distinct ~~~~~~~~ From 70803077d5463327774c3190e3c029b740d5e9cb Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 09:37:05 -0500 Subject: [PATCH 04/20] Test fix --- snooty.toml | 3 +-- source/reference/aggregation.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/snooty.toml b/snooty.toml index 38b23928..19893033 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,5 +1,4 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" -intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] -mdb-server = "MongoDB Server" \ No newline at end of file +intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] \ No newline at end of file diff --git a/source/reference/aggregation.txt b/source/reference/aggregation.txt index a75bbaac..9f1b182c 100644 --- a/source/reference/aggregation.txt +++ b/source/reference/aggregation.txt @@ -104,7 +104,7 @@ find the total number of documents which have the exact array method and may not support the same filters. ``countDocuments`` uses the ``$match`` stage of the aggregation pipeline to filter documents. To learn more about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` - in the {+mdb-server+} documentation. + in the MDB Server documentation. Distinct ~~~~~~~~ From defdd4f9ce041488598a31b463c2ed95411e6c7a Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 09:43:27 -0500 Subject: [PATCH 05/20] Fix --- snooty.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snooty.toml b/snooty.toml index 19893033..d1765ce7 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,4 +1,4 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" -intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] \ No newline at end of file +intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] From 8aaed18a24de4979fdd11d6a7222b649b1ef69bd Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 09:45:55 -0500 Subject: [PATCH 06/20] Try again --- snooty.toml | 1 + source/reference/aggregation.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/snooty.toml b/snooty.toml index d1765ce7..fc127fab 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,4 +1,5 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" +mdb-server = "MongoDB Server" intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] diff --git a/source/reference/aggregation.txt b/source/reference/aggregation.txt index 9f1b182c..a75bbaac 100644 --- a/source/reference/aggregation.txt +++ b/source/reference/aggregation.txt @@ -104,7 +104,7 @@ find the total number of documents which have the exact array method and may not support the same filters. ``countDocuments`` uses the ``$match`` stage of the aggregation pipeline to filter documents. To learn more about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` - in the MDB Server documentation. + in the {+mdb-server+} documentation. Distinct ~~~~~~~~ From 68fbb800e9818039cbcc9ded09946a4396b8f100 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 09:48:00 -0500 Subject: [PATCH 07/20] Never mind --- snooty.toml | 1 - source/reference/aggregation.txt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/snooty.toml b/snooty.toml index fc127fab..d1765ce7 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,5 +1,4 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" -mdb-server = "MongoDB Server" intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] diff --git a/source/reference/aggregation.txt b/source/reference/aggregation.txt index a75bbaac..341a92a5 100644 --- a/source/reference/aggregation.txt +++ b/source/reference/aggregation.txt @@ -104,7 +104,7 @@ find the total number of documents which have the exact array method and may not support the same filters. ``countDocuments`` uses the ``$match`` stage of the aggregation pipeline to filter documents. To learn more about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` - in the {+mdb-server+} documentation. + in the MongoDB Server documentation. Distinct ~~~~~~~~ From 171eaee6c4ca5728ddb8d2f98d4b4c26d7cbe34a Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Mon, 9 Dec 2024 10:29:41 -0500 Subject: [PATCH 08/20] NR suggestion --- source/reference/aggregation.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/reference/aggregation.txt b/source/reference/aggregation.txt index 341a92a5..ee29d556 100644 --- a/source/reference/aggregation.txt +++ b/source/reference/aggregation.txt @@ -104,7 +104,7 @@ find the total number of documents which have the exact array method and may not support the same filters. ``countDocuments`` uses the ``$match`` stage of the aggregation pipeline to filter documents. To learn more about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` - in the MongoDB Server documentation. + in the MongoDB Server manual. Distinct ~~~~~~~~ From 902afa041c87bf1f4fdf81753472d49651479d19 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Thu, 12 Dec 2024 23:53:06 -0500 Subject: [PATCH 09/20] DOCSP-45203 Single Field Indexes --- source/includes/indexes/single-field.rb | 38 ++++++++ source/index.txt | 2 +- source/indexes.txt | 36 +++++++ source/indexes/single-field-index.txt | 122 ++++++++++++++++++++++++ 4 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 source/includes/indexes/single-field.rb create mode 100644 source/indexes.txt create mode 100644 source/indexes/single-field-index.txt diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb new file mode 100644 index 00000000..abb776ca --- /dev/null +++ b/source/includes/indexes/single-field.rb @@ -0,0 +1,38 @@ +require 'mongo' + +# Replace the placeholders with your credentials +uri = "mongodb+srv://lindsey:me123@atlascluster.spm1ztf.mongodb.net/?retryWrites=true&w=majority&appName=AtlasCluster" + +# Set the server_api field of the options object to Stable API version 1 +options = { server_api: { version: "1" }} + +# Create a new client and connect to the server +client = Mongo::Client.new(uri, options) +database = client.use('sample_mflix') +collection = database[:movies] + +# start-index-single +# Create an index on the "title" field +index = collection.indexes.create_one({ title: 1 }) +puts "Index created: #{index}" +# end-index-single + +# start-index-single-query +# Find a document with the title "Sweethearts" +filter = { title: 'Sweethearts' } +doc = collection.find(filter).first + +if doc + puts doc.to_json + else + puts "No document found" + end +# end-index-single-query + +# start-check-single-index +# List all indexes on the collection +all_indexes = collection.indexes +all_indexes.each do |index_spec| + puts index_spec.to_json +end +# end-check-single-index \ No newline at end of file diff --git a/source/index.txt b/source/index.txt index 7f476e11..7464b342 100644 --- a/source/index.txt +++ b/source/index.txt @@ -15,6 +15,7 @@ Get Started Connect Read Data + Indexes View the Source API Documentation <{+api-root+}> @@ -22,7 +23,6 @@ Databases & Collections Write Data Operations on Replica Sets - Indexes Monitor Your Application Data Aggregation Security diff --git a/source/indexes.txt b/source/indexes.txt new file mode 100644 index 00000000..454bb8fd --- /dev/null +++ b/source/indexes.txt @@ -0,0 +1,36 @@ +.. _ruby-indexes: + +================================= +Optimize Queries by Using Indexes +================================= + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :description: Learn how to use indexes by using the MongoDB Scala Driver. + :keywords: query, optimization, efficiency, usage example, code example + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + Single Field +.. Compound +.. Multikey +.. Atlas Search + +Overview +-------- + +On this page, you can see copyable code examples that show how to manage +different types of indexes by using the {+driver-long+}. + +.. TODO diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt new file mode 100644 index 00000000..b6f599ed --- /dev/null +++ b/source/indexes/single-field-index.txt @@ -0,0 +1,122 @@ +.. _ruby-single-field-index: + +==================== +Single Field Indexes +==================== + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: index, query, optimization, efficiency + +Overview +-------- + +Single field indexes are indexes with a reference to a single field of a +document in a collection. These indexes improve single field query and +sort performance. They also support :manual:`TTL Indexes ` +that automatically remove documents from a collection after a certain +amount of time or at a specified clock time. + +When creating a single field index, you must specify the following +details: + +- The field on which to create the index +- The sort order for the indexed values as either ascending or + descending + +.. note:: + + The default ``_id_`` index is an example of a single field index. + This index is automatically created on the ``_id`` field when a new + collection is created. + +Sample Data +~~~~~~~~~~~ + +The examples in this guide use the ``movies`` collection in the +``sample_mflix`` database from the :atlas:`Atlas sample datasets +`. To learn how to create a free MongoDB Atlas cluster and +load the sample datasets, see the :atlas:`Get Started with Atlas +` guide. + +Create a Single Field Index +--------------------------- + +Use the ``createIndex()`` method to create a single +field index. The following example creates an index in ascending order on the +``title`` field: + +.. literalinclude:: /includes/indexes/single-field.rb + :start-after: start-index-single + :end-before: end-index-single + :language: ruby + :copyable: + +Verify the Index's Creation +--------------------------- + +You can verify that the index was created by using the ``listIndexes()`` method. +You should see an index for ``title`` in the list, as shown in the following output: + +.. io-code-block:: + :copyable: true + + .. input:: /includes/indexes/single-field.rb + :start-after: start-check-single-index + :end-before: end-check-single-index + :language: ruby + :dedent: + + .. output:: + :visible: true + + {"v": 2, "key": {"title": 1}, "name": "title_1"} + +Example Query +------------- + +The following is an example of a query that is covered by the index +created on the ``title`` field: + +.. io-code-block:: + :copyable: true + + .. input:: /includes/indexes/single-field.rb + :start-after: start-index-single-query + :end-before: end-index-single-query + :language: ruby + :dedent: + + .. output:: + :visible: false + + {"_id":...,"plot":"A musical comedy duo...", + "genres":["Musical"],...,"title":"Sweethearts",...} + +Additional Information +---------------------- + +To view runnable examples that demonstrate how to manage indexes, see +:ref:`ruby-indexes`. + +To learn more about single field indexes, see :manual:`Single Field +Indexes ` in the {+mdb-server+} manual. + +API Documentation +~~~~~~~~~~~~~~~~~ + +To learn more about any of the methods discussed in this guide, see the +following API documentation: + +- `Collection#indexes<{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ +- `Index::View#create_one <{+api-root+}/Mongo/Index/View.html>`__ +- `Collection#find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ \ No newline at end of file From fff473d8f6a43308e8e6776d0ca57ae2c85c8a0e Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 13 Dec 2024 00:01:44 -0500 Subject: [PATCH 10/20] Edits --- source/includes/indexes/single-field.rb | 4 ++-- source/indexes/single-field-index.txt | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index abb776ca..7425c68f 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -1,7 +1,7 @@ require 'mongo' # Replace the placeholders with your credentials -uri = "mongodb+srv://lindsey:me123@atlascluster.spm1ztf.mongodb.net/?retryWrites=true&w=majority&appName=AtlasCluster" +uri = "" # Set the server_api field of the options object to Stable API version 1 options = { server_api: { version: "1" }} @@ -35,4 +35,4 @@ all_indexes.each do |index_spec| puts index_spec.to_json end -# end-check-single-index \ No newline at end of file +# end-check-single-index diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index b6f599ed..2529aea1 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -51,7 +51,7 @@ load the sample datasets, see the :atlas:`Get Started with Atlas Create a Single Field Index --------------------------- -Use the ``createIndex()`` method to create a single +Use the ``create_one`` method to create a single field index. The following example creates an index in ascending order on the ``title`` field: @@ -64,8 +64,9 @@ field index. The following example creates an index in ascending order on the Verify the Index's Creation --------------------------- -You can verify that the index was created by using the ``listIndexes()`` method. -You should see an index for ``title`` in the list, as shown in the following output: +You can verify that the index was created by iterating through the ``indexes`` object +to list the indexes in the collection. You should see an index for ``title`` in +the list, as shown in the following output: .. io-code-block:: :copyable: true From b9618eff6f8e0a51d4950a21d48af7313e36088d Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 13 Dec 2024 13:36:06 -0500 Subject: [PATCH 11/20] edits --- snooty.toml | 3 ++- source/includes/indexes/single-field.rb | 5 ++++- source/indexes/single-field-index.txt | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/snooty.toml b/snooty.toml index a3a76085..2e3eb5b1 100644 --- a/snooty.toml +++ b/snooty.toml @@ -2,7 +2,8 @@ name = "ruby-driver" title = "Ruby MongoDB Driver" toc_landing_pages = [ "/get-started", - "/connect" + "/connect", + "/indexes" ] intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index 7425c68f..c4f1b6a8 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -8,8 +8,11 @@ # Create a new client and connect to the server client = Mongo::Client.new(uri, options) + +# start-sample-data database = client.use('sample_mflix') collection = database[:movies] +# end-sample-data # start-index-single # Create an index on the "title" field @@ -26,7 +29,7 @@ puts doc.to_json else puts "No document found" - end +end # end-index-single-query # start-check-single-index diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index 2529aea1..6661a5b2 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -44,7 +44,19 @@ Sample Data The examples in this guide use the ``movies`` collection in the ``sample_mflix`` database from the :atlas:`Atlas sample datasets -`. To learn how to create a free MongoDB Atlas cluster and +`. To access this collection from your {+language+} +application, create a ``Mongo::Client`` object that connects to +an Atlas cluster and assign the following values to your ``database`` +and ``collection`` +variables: + +.. literalinclude:: /includes/indexes/single-field.rb + :start-after: start-sample-data + :end-before: end-sample-data + :language: ruby + :copyable: + +To learn how to create a free MongoDB Atlas cluster and load the sample datasets, see the :atlas:`Get Started with Atlas ` guide. @@ -118,6 +130,6 @@ API Documentation To learn more about any of the methods discussed in this guide, see the following API documentation: -- `Collection#indexes<{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ +- `Collection#indexes <{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ - `Index::View#create_one <{+api-root+}/Mongo/Index/View.html>`__ - `Collection#find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ \ No newline at end of file From 10c676cbb6b4b30eb6adfc2ad3c18b292293521b Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 13 Dec 2024 13:52:27 -0500 Subject: [PATCH 12/20] get rid of old commit work --- source/old-content/reference/aggregation.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/source/old-content/reference/aggregation.txt b/source/old-content/reference/aggregation.txt index ee29d556..f9e63f99 100644 --- a/source/old-content/reference/aggregation.txt +++ b/source/old-content/reference/aggregation.txt @@ -98,14 +98,6 @@ find the total number of documents which have the exact array count = coll.count({ 'categories' => [ 'Chinese', 'Seafood' ] }) -.. note:: - - The ``count`` method is not the same as the ``countDocuments`` - method and may not support the same filters. ``countDocuments`` uses the - ``$match`` stage of the aggregation pipeline to filter documents. To learn more - about limitations of the ``$match`` stage, see :manual:`$match Restrictions ` - in the MongoDB Server manual. - Distinct ~~~~~~~~ From de18d3c7e546cf98bf5dd7e50fbb42b9c6322e2a Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 13 Dec 2024 13:58:12 -0500 Subject: [PATCH 13/20] code spacing --- source/includes/indexes/single-field.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index c4f1b6a8..327ab383 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -26,9 +26,9 @@ doc = collection.find(filter).first if doc - puts doc.to_json - else - puts "No document found" + puts doc.to_json +else + puts "No document found" end # end-index-single-query From 565986fbc55913b24c5333d32fc622a05a856a51 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Fri, 13 Dec 2024 18:57:10 -0500 Subject: [PATCH 14/20] Stephanie's reiview --- source/includes/indexes/single-field.rb | 11 +++++------ source/indexes/single-field-index.txt | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index 327ab383..6e3e448f 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -3,10 +3,10 @@ # Replace the placeholders with your credentials uri = "" -# Set the server_api field of the options object to Stable API version 1 +# Sets the server_api field of the options object to Stable API version 1 options = { server_api: { version: "1" }} -# Create a new client and connect to the server +# Creates a new client and connect to the server client = Mongo::Client.new(uri, options) # start-sample-data @@ -15,13 +15,12 @@ # end-sample-data # start-index-single -# Create an index on the "title" field +# Creates an index on the "title" field index = collection.indexes.create_one({ title: 1 }) -puts "Index created: #{index}" # end-index-single # start-index-single-query -# Find a document with the title "Sweethearts" +# Finds a document with the title "Sweethearts" filter = { title: 'Sweethearts' } doc = collection.find(filter).first @@ -33,7 +32,7 @@ # end-index-single-query # start-check-single-index -# List all indexes on the collection +# Lists all indexes on the collection all_indexes = collection.indexes all_indexes.each do |index_spec| puts index_spec.to_json diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index 6661a5b2..8bfdf42a 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -73,8 +73,8 @@ field index. The following example creates an index in ascending order on the :language: ruby :copyable: -Verify the Index's Creation ---------------------------- +Verify Index Creation +--------------------- You can verify that the index was created by iterating through the ``indexes`` object to list the indexes in the collection. You should see an index for ``title`` in From 343569bd2b4dade209c90a5e0bc9ddc31bb06d49 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 15:27:47 -0500 Subject: [PATCH 15/20] Tech review code improvements --- source/includes/indexes/single-field.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index 6e3e448f..da805b14 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -16,7 +16,7 @@ # start-index-single # Creates an index on the "title" field -index = collection.indexes.create_one({ title: 1 }) +collection.indexes.create_one({ title: 1 }) # end-index-single # start-index-single-query @@ -33,8 +33,5 @@ # start-check-single-index # Lists all indexes on the collection -all_indexes = collection.indexes -all_indexes.each do |index_spec| - puts index_spec.to_json -end +puts collection.indexes.collect(&:to_json) # end-check-single-index From 06ff75ee07fc4dd5821ed31d5db5b17a36f66f99 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 16:08:22 -0500 Subject: [PATCH 16/20] update api links --- source/indexes/single-field-index.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index 8bfdf42a..7e4505f7 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -130,6 +130,6 @@ API Documentation To learn more about any of the methods discussed in this guide, see the following API documentation: -- `Collection#indexes <{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ -- `Index::View#create_one <{+api-root+}/Mongo/Index/View.html>`__ -- `Collection#find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ \ No newline at end of file +- `indexes <{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ +- `create_one <{+api-root+}/Mongo/Index/View.html>`__ +- `find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ \ No newline at end of file From 109c4b3c184c2b05a53f07c2d02dff8ed139df83 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 16:09:43 -0500 Subject: [PATCH 17/20] add a space at eof --- source/indexes/single-field-index.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index 7e4505f7..6ece8757 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -132,4 +132,4 @@ following API documentation: - `indexes <{+api-root+}/Mongo/Collection.html#indexes-instance_method>`__ - `create_one <{+api-root+}/Mongo/Index/View.html>`__ -- `find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ \ No newline at end of file +- `find <{+api-root+}/Mongo/Collection.html#find-instance_method>`__ From 3425c77f45aadc9faa83080a3a805ca1a8cac3f3 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 16:26:55 -0500 Subject: [PATCH 18/20] update listing description --- source/indexes/single-field-index.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/indexes/single-field-index.txt b/source/indexes/single-field-index.txt index 6ece8757..61cf10d5 100644 --- a/source/indexes/single-field-index.txt +++ b/source/indexes/single-field-index.txt @@ -76,9 +76,9 @@ field index. The following example creates an index in ascending order on the Verify Index Creation --------------------- -You can verify that the index was created by iterating through the ``indexes`` object -to list the indexes in the collection. You should see an index for ``title`` in -the list, as shown in the following output: +You can verify that the index was created by listing the indexes in the +collection. You should see an index for ``title`` in the list, as shown +in the following output: .. io-code-block:: :copyable: true From 1ef955ce6a461e12e62b19deceb15e5992f0f356 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 17:25:31 -0500 Subject: [PATCH 19/20] add context to ex query code comment --- source/includes/indexes/single-field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index da805b14..5d92e693 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -20,7 +20,7 @@ # end-index-single # start-index-single-query -# Finds a document with the title "Sweethearts" +# Finds a document with the title "Sweethearts", using the newly created index filter = { title: 'Sweethearts' } doc = collection.find(filter).first From 273de71fd6ef45b16ae28ac7ecd40bd52c9b8779 Mon Sep 17 00:00:00 2001 From: Lindsey Moore Date: Mon, 16 Dec 2024 17:29:40 -0500 Subject: [PATCH 20/20] style edit on prev --- source/includes/indexes/single-field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/includes/indexes/single-field.rb b/source/includes/indexes/single-field.rb index 5d92e693..bbf1ff95 100644 --- a/source/includes/indexes/single-field.rb +++ b/source/includes/indexes/single-field.rb @@ -20,7 +20,7 @@ # end-index-single # start-index-single-query -# Finds a document with the title "Sweethearts", using the newly created index +# Finds a document with the title "Sweethearts" by using the newly created index filter = { title: 'Sweethearts' } doc = collection.find(filter).first