diff --git a/config/redirects b/config/redirects index b5c6f75d..0b01bbbf 100644 --- a/config/redirects +++ b/config/redirects @@ -124,3 +124,34 @@ raw: ${prefix}/stable -> ${base}/current/ (v2.20-*]: ${prefix}/${version}/reference/search-indexes/ -> ${base}/${version}/indexes/atlas-search-index/ (v2.20-*]: ${prefix}/${version}/reference/collations/ -> ${base}/${version}/read/collations/ (v2.20-*]: ${prefix}/${version}/contribute/ -> ${base}/${version}/issues-and-help/ + +# Comprehensive coverage TOC shift + +(*-master) ${prefix}/${version}/get-started/download-and-install/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/get-started/create-a-deployment/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/get-started/create-a-connection-string/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/get-started/connect-to-mongodb/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/get-started/next-steps/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/databases-collections/ -> ${base}/${version}/get-started/ +(*-master) ${prefix}/${version}/write/insert/ -> ${base}/${version}/crud/insert/ +(*-master) ${prefix}/${version}/read/retrieve/ -> ${base}/${version}/crud/query/ +(*-master) ${prefix}/${version}/write/update/ -> ${base}/${version}/crud/update/ +(*-master) ${prefix}/${version}/write/replace/ -> ${base}/${version}/crud/replace/ +(*-master) ${prefix}/${version}/write/delete/ -> ${base}/${version}/crud/delete/ +(*-master) ${prefix}/${version}/write/bulk-write/ -> ${base}/${version}/crud/bulk-write/ +(*-master) ${prefix}/${version}/write/transactions/ -> ${base}/${version}/crud/transactions/ +(*-master) ${prefix}/${version}/read-write-pref/ -> ${base}/${version}/crud/configure-crud/ +(*-master) ${prefix}/${version}/read/collations/ -> ${base}/${version}/crud/collations/ +(*-master) ${prefix}/${version}/write/gridfs/ -> ${base}/${version}/crud/gridfs/ +(*-master) ${prefix}/${version}/read/count/ -> ${base}/${version}/crud/query/count +(*-master) ${prefix}/${version}/read/retrieve/ -> ${base}/${version}/crud/query/find +(*-master) ${prefix}/${version}/read/project/ -> ${base}/${version}/crud/query/project +(*-master) ${prefix}/${version}/read/specify-documents-to-return/ -> ${base}/${version}/crud/query/specify-documents-to-return +(*-master) ${prefix}/${version}/read/distinct/ -> ${base}/${version}/crud/query/distinct +(*-master) ${prefix}/${version}/read/cursors/ -> ${base}/${version}/crud/query/cursors +(*-master) ${prefix}/${version}/read/specify-a-query/ -> ${base}/${version}/crud/query/specify-a-query +(*-master) ${prefix}/${version}/databases-collections/run-command -> ${base}/${version}/run-command +(*-master) ${prefix}/${version}/monitoring/cluster-monitoring -> ${base}/${version}/logging-and-monitoring/cluster-monitoring +(*-master) ${prefix}/${version}/read/change-streams/ -> ${base}/${version}/logging-and-monitoring/change-streams +(*-master) ${prefix}/${version}/connect/tls/ -> ${base}/${version}/security/tls +(*-master) ${prefix}/${version}/common-errors/ -> ${base}/${version}/ diff --git a/snooty.toml b/snooty.toml index 1d847082..7d7ee58b 100644 --- a/snooty.toml +++ b/snooty.toml @@ -1,12 +1,9 @@ name = "ruby-driver" title = "Ruby Driver" toc_landing_pages = [ - "/get-started", - "/read", - "/write", + "/crud/query", "/indexes", - "/databases-collection", - "/security/authentication", + "/security/authentication" ] intersphinx = ["https://www.mongodb.com/docs/manual/objects.inv"] diff --git a/source/atlas-search.txt b/source/atlas-search.txt new file mode 100644 index 00000000..9dc35706 --- /dev/null +++ b/source/atlas-search.txt @@ -0,0 +1,5 @@ +.. _ruby-atlas-search + +============ +Atlas Search +============ diff --git a/source/crud.txt b/source/crud.txt new file mode 100644 index 00000000..b0056cc0 --- /dev/null +++ b/source/crud.txt @@ -0,0 +1,20 @@ +=============== +CRUD Operations +=============== + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + Insert Documents + Query Documents + Update Documents + Replace Documents + Delete Documents + Bulk Write Operations + Transactions + Configure CRUD Operations + Retryable Reads + Retryable Writes + Collation + Store Large Files \ No newline at end of file diff --git a/source/write/bulk-write.txt b/source/crud/bulk-write.txt similarity index 100% rename from source/write/bulk-write.txt rename to source/crud/bulk-write.txt diff --git a/source/read/collations.txt b/source/crud/collations.txt similarity index 99% rename from source/read/collations.txt rename to source/crud/collations.txt index c607409f..85df632a 100644 --- a/source/read/collations.txt +++ b/source/crud/collations.txt @@ -1,7 +1,7 @@ .. _ruby-collations: ========== -Collations +Collation ========== .. default-domain:: mongodb diff --git a/source/read-write-pref.txt b/source/crud/configure-crud.txt similarity index 98% rename from source/read-write-pref.txt rename to source/crud/configure-crud.txt index e6b6ea74..530beadd 100644 --- a/source/read-write-pref.txt +++ b/source/crud/configure-crud.txt @@ -1,8 +1,8 @@ .. _ruby-crud-write-read-pref: -=============================== -CRUD Operations on Replica Sets -=============================== +========================= +Configure CRUD Operations +========================= .. facet:: :name: genre diff --git a/source/write/delete.txt b/source/crud/delete.txt similarity index 100% rename from source/write/delete.txt rename to source/crud/delete.txt diff --git a/source/write/gridfs.txt b/source/crud/gridfs.txt similarity index 100% rename from source/write/gridfs.txt rename to source/crud/gridfs.txt diff --git a/source/write/insert.txt b/source/crud/insert.txt similarity index 100% rename from source/write/insert.txt rename to source/crud/insert.txt diff --git a/source/read.txt b/source/crud/query.txt similarity index 91% rename from source/read.txt rename to source/crud/query.txt index e8c6e83d..a3834e53 100644 --- a/source/read.txt +++ b/source/crud/query.txt @@ -1,8 +1,8 @@ .. _ruby-read: -====================== -Read Data from MongoDB -====================== +=============== +Query Documents +=============== .. contents:: On this page :local: @@ -23,7 +23,6 @@ Read Data from MongoDB :maxdepth: 1 Retrieve Data - Specify a Query Specify Documents to Return Specify Fields to Return Distinct Field Values @@ -32,6 +31,19 @@ Read Data from MongoDB Monitor Changes Collations + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + Find Documents + Specify a Query + Specify Documents to Return + Specify Fields to Return + Count Documents + Distinct Field Values + Access Data from a Cursor + Overview -------- diff --git a/source/read/count.txt b/source/crud/query/count.txt similarity index 100% rename from source/read/count.txt rename to source/crud/query/count.txt diff --git a/source/read/cursors.txt b/source/crud/query/cursors.txt similarity index 100% rename from source/read/cursors.txt rename to source/crud/query/cursors.txt diff --git a/source/read/distinct.txt b/source/crud/query/distinct.txt similarity index 100% rename from source/read/distinct.txt rename to source/crud/query/distinct.txt diff --git a/source/read/retrieve.txt b/source/crud/query/find.txt similarity index 98% rename from source/read/retrieve.txt rename to source/crud/query/find.txt index ccddb763..d513c25d 100644 --- a/source/read/retrieve.txt +++ b/source/crud/query/find.txt @@ -1,8 +1,8 @@ .. _ruby-retrieve: -============= -Retrieve Data -============= +============== +Find Documents +============== .. contents:: On this page :local: @@ -15,7 +15,7 @@ Retrieve Data :values: reference .. meta:: - :keywords: code examples, read, query, cursor + :keywords: code examples, read, query, cursor, find Overview -------- diff --git a/source/read/project.txt b/source/crud/query/project.txt similarity index 100% rename from source/read/project.txt rename to source/crud/query/project.txt diff --git a/source/read/specify-a-query.txt b/source/crud/query/specify-a-query.txt similarity index 100% rename from source/read/specify-a-query.txt rename to source/crud/query/specify-a-query.txt diff --git a/source/read/specify-documents-to-return.txt b/source/crud/query/specify-documents-to-return.txt similarity index 100% rename from source/read/specify-documents-to-return.txt rename to source/crud/query/specify-documents-to-return.txt diff --git a/source/write/replace.txt b/source/crud/replace.txt similarity index 100% rename from source/write/replace.txt rename to source/crud/replace.txt diff --git a/source/crud/retryable-reads.txt b/source/crud/retryable-reads.txt new file mode 100644 index 00000000..36ea1405 --- /dev/null +++ b/source/crud/retryable-reads.txt @@ -0,0 +1,18 @@ +.. _ruby-crud-retryable-reads: + +=============== +Retryable Reads +=============== + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: timeout + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol \ No newline at end of file diff --git a/source/crud/retryable-writes.txt b/source/crud/retryable-writes.txt new file mode 100644 index 00000000..d1e2c93f --- /dev/null +++ b/source/crud/retryable-writes.txt @@ -0,0 +1,18 @@ +.. _ruby-crud-retryable-writes: + +================ +Retryable Writes +================ + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: timeout + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol \ No newline at end of file diff --git a/source/write/transactions.txt b/source/crud/transactions.txt similarity index 100% rename from source/write/transactions.txt rename to source/crud/transactions.txt diff --git a/source/write/update.txt b/source/crud/update.txt similarity index 100% rename from source/write/update.txt rename to source/crud/update.txt diff --git a/source/databases-collection.txt b/source/databases-collection.txt deleted file mode 100644 index 9aadd2ce..00000000 --- a/source/databases-collection.txt +++ /dev/null @@ -1,264 +0,0 @@ -.. _ruby-databases-collections: - -========================= -Databases and Collections -========================= - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: table, row, organize, storage - -.. toctree:: - :titlesonly: - :maxdepth: 1 - - Run a Command - -Overview --------- - -In this guide, you can learn how to use MongoDB databases and -collections with {+driver-short+}. - -MongoDB organizes data into a hierarchy of the following levels: - -- **Databases**: The top level of data organization in a MongoDB instance. -- **Collections**: MongoDB stores documents in collections. They are analogous to tables in relational databases. -- **Documents**: Contain literal data such as string, numbers, dates, and other embedded documents. - -For more information about document field types and structure, see the -:manual:`Documents ` guide in the {+mdb-server+} manual. - -.. TODO: Add a diagram here - -Access a Database ------------------ - -Access a database by creating a ``Mongo::Client`` instance with the desired -database name. - -The following example accesses a database named ``test_database``: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-access-db - :end-before: end-access-db - - -Access a Collection -------------------- - -Access a collection by using the ``[]`` method on an instance -of your database. - -The following example accesses a collection named ``test_collection``: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :emphasize-lines: 2 - :start-after: start-access-cl - :end-before: end-access-cl - -.. tip:: - - If the provided collection name does not already exist in the database, - MongoDB implicitly creates the collection when you first insert data - into it. - -Create a Collection -------------------- - -While the Ruby driver for MongoDB does not have a direct ``create_collection`` -method, you can use the ``create`` method to create a collection with -specific options. - -The following example creates a collection called example_collection with -specific options: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :emphasize-lines: 3 - :start-after: start-create-collection - :end-before: end-create-collection - -You can specify collection options such as maximum size, document validation -rules, and others by passing them as arguments to the command method with the -create command. For a full list of optional parameters, refer to the MongoDB -documentation on the :manual:`create command `. - -Get a List of Collections -------------------------- - -You can query for a list of collections in a database by calling the ``collections`` -method. This method returns an array of collection objects in the database. - -The following example calls the ``collections`` method and iterates over the array -to print the results: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-get-list - :end-before: end-get-list - -To query for only the names of the collections in the database, call the -``collection_names`` method as follows: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-get-list-names - :end-before: end-get-list-names - -.. note:: - - The ``database.collections`` objects list provides more detailed information - (i.e. each collection object can be further queried for metadata), while - ``database.collection_names`` simply lists the collection names. - -Delete a Collection -------------------- - -You can delete a collection from the database by using the ``drop`` method. - -The following example deletes the ``test_collection`` collection: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-delete - :end-before: end-delete - -.. warning:: Dropping a Collection Deletes All Data in the Collection - - Dropping a collection from your database permanently deletes all - documents and all indexes within that collection. - - Drop a collection only if the data in it is no longer needed. - -.. _ruby-config-read-write: - -Configure Read and Write Operations ------------------------------------ - -You can control how the driver routes read operations by setting a **read preference**. -You can also control options for how the driver waits for acknowledgment of -read and write operations on a replica set by setting a **read concern** and a -**write concern**. - -By default, databases inherit these settings from the ``Mongo::Client`` instance, -and collections inherit them from the database. However, you can change these -settings on your database or collection by using one of the following methods: - -- ``database.with``: Gets the database and applies the new read preference, read - concern, and write concern. -- ``collection.with``: Gets the collection and applies the new read preference, - read concern, and write concern. - -To change read or write settings with the preceding methods, call the method and -pass in the new read preference, read concern, or write concern. - -The following example shows how to change the read preference, read concern, and -write preference of a database called ``test-database`` with the ``database.with`` -method: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-with-database - :end-before: end-with-database - -The following example shows how to change the read preference, read concern, and -write concern of a collection: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-with-collection - :end-before: end-with-collection - -To learn more about the read and write settings, see the following guides in the -MongoDB Server manual: - -- :manual:`Read Preference ` -- :manual:`Read Concern ` -- :manual:`Write Concern ` - -Tag Sets -~~~~~~~~ - -In {+mdb-server+}, you can apply key-value :manual:`tags -` to replica set -members according to any criteria you choose. You can then use -those tags to target one or more members for a read operation. - -By default, the MongoDB {+driver-short+} selects primary members for read operations. -You can modify this behavior by setting read preferences and, optionally, tag sets. - -In the following code example, the tag set passed to the ``:read`` parameter -instructs the {+driver-short+} to prefer reads from the New York data center -(``'dc':'ny'``) and to fall back to the San Francisco data center (``'dc':'sf'``): - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-tag-sets - :end-before: end-tag-sets - -To learn more about replica sets, see the the MongoDB Server manual -:manual:`Replica Set Members ` page. - -Local Threshold -~~~~~~~~~~~~~~~ - -If multiple replica set members match the read preference and tag sets you specify, -{+driver-short+} reads from the nearest replica set members of sharded clusters, -chosen according to their ping time. - -By default, the driver uses only those members whose ping times are within 15 milliseconds -of the nearest member for queries. To distribute reads between members with -higher latencies, pass the ``local_threshold`` option to the ``Mongo::Client`` constructor. - -The following example specifies a local threshold of 35 milliseconds: - -.. literalinclude:: /includes/usage-examples/databases-collection.rb - :language: ruby - :dedent: - :start-after: start-local-threshold-example - :end-before: end-local-threshold-example - :emphasize-lines: 5 - -In the preceding example, {+driver-short+} distributes reads between matching members -within 35 milliseconds of the closest member's ping time. - -.. note:: - - {+driver-short+} ignores the value of ``local_threshold`` when communicating with a - replica set through a ``mongos`` instance. In this case, use the - :manual:`localThreshold ` - command-line option. - -API Documentation ------------------ - -To learn more about any of the methods or types discussed in this -guide, see the following API documentation: - -- :ruby-api:`collections ` -- :ruby-api:`collection_names ` -- :ruby-api:`command ` -- :ruby-api:`drop database ` -- :ruby-api:`drop collection ` -- :ruby-api:`with ` diff --git a/source/get-started.txt b/source/get-started.txt index bb100e54..92df65b4 100644 --- a/source/get-started.txt +++ b/source/get-started.txt @@ -7,7 +7,7 @@ Get Started with the Ruby Driver .. contents:: On this page :local: :backlinks: none - :depth: 2 + :depth: 3 :class: singlecol .. facet:: @@ -16,15 +16,7 @@ Get Started with the Ruby Driver .. meta:: :description: Learn how to create an app to connect to MongoDB deployment by using the Ruby driver. - :keywords: quick start, tutorial, basics - -.. toctree:: - - Download & Install - Create a Deployment - Create a Connection String - Connect to MongoDB - Next Steps + :keywords: quick start, tutorial, basics, installation, setup, code example, test connection, runnable Overview -------- @@ -44,3 +36,454 @@ and query data in your cluster. If you prefer to use a different driver or programming language to connect to MongoDB, see our :driver:`list of official drivers <>`. +.. include:: /includes/get-started/troubleshoot.rst + +.. _ruby-quick-start-download-and-install: + +Download and Install +-------------------- + +.. procedure:: + :style: connected + + .. step:: Install dependencies + + Before you begin developing, ensure you install `Ruby + `__ version 2.7 + or later in your development environment. {+language+} + is pre-installed on macOS and some Linux distributions, + but you might need to update your version. + + .. important:: + + The {+driver-short+} is not officially supported on Windows. + + .. step:: Create a project directory + + Run the following command in your shell to create a directory + called ``ruby-quickstart`` for this project: + + .. code-block:: bash + + mkdir ruby-quickstart + + Then, run the following commands to create a ``quickstart.rb`` file in + the ``ruby-quickstart`` directory: + + .. code-block:: bash + + cd ruby-quickstart + touch quickstart.rb + + .. step:: Add the {+driver-short+} to your project + + Open the ``quickstart.rb`` file and add the following code: + + .. literalinclude:: /includes/get-started/quickstart.rb + :language: ruby + :dedent: + :start-after: start-bundler + :end-before: end-bundler + + This code adds the {+driver-short+} as a dependency by + using the `Bundler `__ dependency management tool. + +After you complete these steps, you have a new project directory with the driver +dependencies installed. + +.. _ruby-get-started-create-deployment: + +Create a MongoDB Deployment +--------------------------- + +You can create a free tier MongoDB deployment on MongoDB Atlas +to store and manage your data. MongoDB Atlas hosts and manages +your MongoDB database in the cloud. + +.. procedure:: + :style: connected + + .. step:: Create a free MongoDB deployment on Atlas + + Complete the :atlas:`Get Started with Atlas ` + guide to set up a new Atlas account and load sample data into a new free + tier MongoDB deployment. + + .. step:: Save your credentials + + After you create your database user, save that user's + username and password to a safe location for use in an upcoming step. + +After you complete these steps, you have a new free tier MongoDB +deployment on Atlas, database user credentials, and sample data loaded +in your database. + +.. _ruby-get-started-connection-string: + +Create a Connection String +-------------------------- + +You can connect to your MongoDB deployment by providing a +**connection URI**, also called a *connection string*, which +instructs the driver how to connect to a MongoDB deployment +and how to behave while connected. + +The connection string includes the hostname or IP address and +port of your deployment, the authentication mechanism, user credentials +when applicable, and connection options. + +To learn how to connect to an instance or deployment not hosted on +Atlas, see the :ref:`ruby-connection-targets` guide. + +.. procedure:: + :style: connected + + .. step:: Find your MongoDB Atlas connection string + + To retrieve your connection string for the deployment that + you created in the :ref:`previous step `, + log in to your Atlas account and navigate to the + :guilabel:`Clusters` section. Then, click the :guilabel:`Connect` button + for your new deployment. + + .. figure:: /includes/figures/atlas_connection_connect_cluster.png + :alt: The connect button in the clusters section of the Atlas UI + + Proceed to the :guilabel:`Connect your application` section. Select + "Ruby" from the :guilabel:`Driver` selection menu and the version + that best matches your installed version from the :guilabel:`Version` + selection menu. + + .. step:: Copy your connection string + + Click the copy button on the right of the connection string to copy it to + your clipboard, as shown in the following screenshot: + + .. figure:: /includes/figures/atlas_connection_copy_string_ruby.png + :alt: The connection string copy button in the Atlas UI + + .. step:: Update the placeholders + + Paste this connection string into a file in your preferred text editor + and replace the ```` and ```` placeholders with + your database user's username and password. + + Save this file to a safe location for use in the next step. + +After completing these steps, you have a connection string that +contains your database username and password. + +.. _ruby-get-started-connect-to-mongodb: + +Connect to MongoDB +------------------ + +.. procedure:: + :style: connected + + .. step:: Edit your {+language+} application file + + Navigate to your ``quickstart.rb`` file in the ``ruby-quickstart`` + directory. Copy and paste the following code below the Bundler + code from the :ref:`ruby-quick-start-download-and-install` step + of this tutorial. This code connects to MongoDB and queries the + ``movies`` collection in the ``sample_mflix`` database. + + .. literalinclude:: /includes/get-started/quickstart.rb + :language: ruby + :dedent: + :start-after: start-query + :end-before: end-query + + .. step:: Assign the connection string + + Replace the ```` placeholder with the + connection string that you copied from the :ref:`ruby-get-started-connection-string` + step of this tutorial. + + .. step:: Run your {+language+} application + + From your ``ruby-quickstart`` directory, run the following shell + command to run the application: + + .. code-block:: none + + ruby quickstart.rb + + The command line output contains details about the retrieved movie + document: + + .. code-block:: none + :copyable: false + + {"_id"=>BSON::ObjectId('...'), "plot"=>"A young man is accidentally sent + 30 years into the past in a time-traveling DeLorean invented by his friend, + Dr. Emmett Brown, and must make sure his high-school-age parents unite + in order to save his own existence.", ... + "title"=>"Back to the Future", ... + + If you encounter an error or see no output, ensure that you specified the + correct connection string in the ``quickstart.rb`` file and that you loaded the + sample data. + +After you complete these steps, you have a working application that +uses the driver to connect to your MongoDB deployment, runs a query on +the sample data, and prints out the result. + +.. _ruby-databases-collections: + +Manage your Databases and Collections +------------------------------------- + +You can learn how to use MongoDB databases and +collections with {+driver-short+}. + +MongoDB organizes data into a hierarchy of the following levels: + +- **Databases**: The top level of data organization in a MongoDB instance. +- **Collections**: MongoDB stores documents in collections. They are analogous to tables in relational databases. +- **Documents**: Contain literal data such as string, numbers, dates, and other embedded documents. + +For more information about document field types and structure, see the +:manual:`Documents ` guide in the {+mdb-server+} manual. + +.. TODO: Add a diagram here + +Access a Database +~~~~~~~~~~~~~~~~~ + +Access a database by creating a ``Mongo::Client`` instance with the desired +database name. + +The following example accesses a database named ``test_database``: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-access-db + :end-before: end-access-db + + +Access a Collection +~~~~~~~~~~~~~~~~~~~ + +Access a collection by using the ``[]`` method on an instance +of your database. + +The following example accesses a collection named ``test_collection``: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :emphasize-lines: 2 + :start-after: start-access-cl + :end-before: end-access-cl + +.. tip:: + + If the provided collection name does not already exist in the database, + MongoDB implicitly creates the collection when you first insert data + into it. + +Create a Collection +~~~~~~~~~~~~~~~~~~~ + +While the Ruby driver for MongoDB does not have a direct ``create_collection`` +method, you can use the ``create`` method to create a collection with +specific options. + +The following example creates a collection called example_collection with +specific options: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :emphasize-lines: 3 + :start-after: start-create-collection + :end-before: end-create-collection + +You can specify collection options such as maximum size, document validation +rules, and others by passing them as arguments to the command method with the +create command. For a full list of optional parameters, refer to the MongoDB +documentation on the :manual:`create command `. + +Get a List of Collections +~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can query for a list of collections in a database by calling the ``collections`` +method. This method returns an array of collection objects in the database. + +The following example calls the ``collections`` method and iterates over the array +to print the results: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-get-list + :end-before: end-get-list + +To query for only the names of the collections in the database, call the +``collection_names`` method as follows: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-get-list-names + :end-before: end-get-list-names + +.. note:: + + The ``database.collections`` objects list provides more detailed information + (i.e. each collection object can be further queried for metadata), while + ``database.collection_names`` simply lists the collection names. + +Delete a Collection +~~~~~~~~~~~~~~~~~~~ + +You can delete a collection from the database by using the ``drop`` method. + +The following example deletes the ``test_collection`` collection: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-delete + :end-before: end-delete + +.. warning:: Dropping a Collection Deletes All Data in the Collection + + Dropping a collection from your database permanently deletes all + documents and all indexes within that collection. + + Drop a collection only if the data in it is no longer needed. + +.. _ruby-config-read-write: + +Configure Read and Write Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can control how the driver routes read operations by setting a **read preference**. +You can also control options for how the driver waits for acknowledgment of +read and write operations on a replica set by setting a **read concern** and a +**write concern**. + +By default, databases inherit these settings from the ``Mongo::Client`` instance, +and collections inherit them from the database. However, you can change these +settings on your database or collection by using one of the following methods: + +- ``database.with``: Gets the database and applies the new read preference, read + concern, and write concern. +- ``collection.with``: Gets the collection and applies the new read preference, + read concern, and write concern. + +To change read or write settings with the preceding methods, call the method and +pass in the new read preference, read concern, or write concern. + +The following example shows how to change the read preference, read concern, and +write preference of a database called ``test-database`` with the ``database.with`` +method: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-with-database + :end-before: end-with-database + +The following example shows how to change the read preference, read concern, and +write concern of a collection: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-with-collection + :end-before: end-with-collection + +To learn more about the read and write settings, see the following guides in the +MongoDB Server manual: + +- :manual:`Read Preference ` +- :manual:`Read Concern ` +- :manual:`Write Concern ` + +Tag Sets +```````` + +In {+mdb-server+}, you can apply key-value :manual:`tags +` to replica set +members according to any criteria you choose. You can then use +those tags to target one or more members for a read operation. + +By default, the MongoDB {+driver-short+} selects primary members for read operations. +You can modify this behavior by setting read preferences and, optionally, tag sets. + +In the following code example, the tag set passed to the ``:read`` parameter +instructs the {+driver-short+} to prefer reads from the New York data center +(``'dc':'ny'``) and to fall back to the San Francisco data center (``'dc':'sf'``): + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-tag-sets + :end-before: end-tag-sets + +To learn more about replica sets, see the the MongoDB Server manual +:manual:`Replica Set Members ` page. + +Local Threshold +```````````````` + +If multiple replica set members match the read preference and tag sets you specify, +{+driver-short+} reads from the nearest replica set members of sharded clusters, +chosen according to their ping time. + +By default, the driver uses only those members whose ping times are within 15 milliseconds +of the nearest member for queries. To distribute reads between members with +higher latencies, pass the ``local_threshold`` option to the ``Mongo::Client`` constructor. + +The following example specifies a local threshold of 35 milliseconds: + +.. literalinclude:: /includes/usage-examples/databases-collection.rb + :language: ruby + :dedent: + :start-after: start-local-threshold-example + :end-before: end-local-threshold-example + :emphasize-lines: 5 + +In the preceding example, {+driver-short+} distributes reads between matching members +within 35 milliseconds of the closest member's ping time. + +.. note:: + + {+driver-short+} ignores the value of ``local_threshold`` when communicating with a + replica set through a ``mongos`` instance. In this case, use the + :manual:`localThreshold ` + command-line option. + +API Documentation +~~~~~~~~~~~~~~~~~ + +To learn more about any of the methods or types discussed in this +guide, see the following API documentation: + +- :ruby-api:`collections ` +- :ruby-api:`collection_names ` +- :ruby-api:`command ` +- :ruby-api:`drop database ` +- :ruby-api:`drop collection ` +- :ruby-api:`with ` + +.. _ruby-get-started-next-steps: + +Next Steps +---------- + +Congratulations on completing the quick start tutorial! + +In this tutorial, you created a {+language+} application that +connects to a MongoDB deployment hosted on MongoDB Atlas +and retrieves a document that matches a query. + +Learn more about the {+driver-short+} from the following resources: + +- Learn how to perform read operations in the :ref:`` section. +- Learn how to perform write operations in the :ref:`` section. diff --git a/source/get-started/connect-to-mongodb.txt b/source/get-started/connect-to-mongodb.txt deleted file mode 100644 index 40702b27..00000000 --- a/source/get-started/connect-to-mongodb.txt +++ /dev/null @@ -1,66 +0,0 @@ -.. _ruby-get-started-connect-to-mongodb: - -================== -Connect to MongoDB -================== - -.. facet:: - :name: genre - :values: tutorial - -.. meta:: - :keywords: test connection, runnable, code example - -.. procedure:: - :style: connected - - .. step:: Edit your {+language+} application file - - Navigate to your ``quickstart.rb`` file in the ``ruby-quickstart`` - directory. Copy and paste the following code below the Bundler - code from the :ref:`ruby-quick-start-download-and-install` step - of this tutorial. This code connects to MongoDB and queries the - ``movies`` collection in the ``sample_mflix`` database. - - .. literalinclude:: /includes/get-started/quickstart.rb - :language: ruby - :dedent: - :start-after: start-query - :end-before: end-query - - .. step:: Assign the connection string - - Replace the ```` placeholder with the - connection string that you copied from the :ref:`ruby-get-started-connection-string` - step of this tutorial. - - .. step:: Run your {+language+} application - - From your ``ruby-quickstart`` directory, run the following shell - command to run the application: - - .. code-block:: none - - ruby quickstart.rb - - The command line output contains details about the retrieved movie - document: - - .. code-block:: none - :copyable: false - - {"_id"=>BSON::ObjectId('...'), "plot"=>"A young man is accidentally sent - 30 years into the past in a time-traveling DeLorean invented by his friend, - Dr. Emmett Brown, and must make sure his high-school-age parents unite - in order to save his own existence.", ... - "title"=>"Back to the Future", ... - - If you encounter an error or see no output, ensure that you specified the - correct connection string in the ``quickstart.rb`` file and that you loaded the - sample data. - -After you complete these steps, you have a working application that -uses the driver to connect to your MongoDB deployment, runs a query on -the sample data, and prints out the result. - -.. include:: /includes/get-started/troubleshoot.rst diff --git a/source/get-started/create-a-connection-string.txt b/source/get-started/create-a-connection-string.txt deleted file mode 100644 index 89e373e2..00000000 --- a/source/get-started/create-a-connection-string.txt +++ /dev/null @@ -1,57 +0,0 @@ -.. _ruby-get-started-connection-string: - -========================== -Create a Connection String -========================== - -You can connect to your MongoDB deployment by providing a -**connection URI**, also called a *connection string*, which -instructs the driver how to connect to a MongoDB deployment -and how to behave while connected. - -The connection string includes the hostname or IP address and -port of your deployment, the authentication mechanism, user credentials -when applicable, and connection options. - -To learn how to connect to an instance or deployment not hosted on -Atlas, see the :ref:`ruby-connection-targets` guide. - -.. procedure:: - :style: connected - - .. step:: Find your MongoDB Atlas connection string - - To retrieve your connection string for the deployment that - you created in the :ref:`previous step `, - log in to your Atlas account and navigate to the - :guilabel:`Clusters` section. Then, click the :guilabel:`Connect` button - for your new deployment. - - .. figure:: /includes/figures/atlas_connection_connect_cluster.png - :alt: The connect button in the clusters section of the Atlas UI - - Proceed to the :guilabel:`Connect your application` section. Select - "Ruby" from the :guilabel:`Driver` selection menu and the version - that best matches your installed version from the :guilabel:`Version` - selection menu. - - .. step:: Copy your connection string - - Click the copy button on the right of the connection string to copy it to - your clipboard, as shown in the following screenshot: - - .. figure:: /includes/figures/atlas_connection_copy_string_ruby.png - :alt: The connection string copy button in the Atlas UI - - .. step:: Update the placeholders - - Paste this connection string into a file in your preferred text editor - and replace the ```` and ```` placeholders with - your database user's username and password. - - Save this file to a safe location for use in the next step. - -After completing these steps, you have a connection string that -contains your database username and password. - -.. include:: /includes/get-started/troubleshoot.rst \ No newline at end of file diff --git a/source/get-started/create-a-deployment.txt b/source/get-started/create-a-deployment.txt deleted file mode 100644 index e19b53c1..00000000 --- a/source/get-started/create-a-deployment.txt +++ /dev/null @@ -1,29 +0,0 @@ -.. _ruby-get-started-create-deployment: - -=========================== -Create a MongoDB Deployment -=========================== - -You can create a free tier MongoDB deployment on MongoDB Atlas -to store and manage your data. MongoDB Atlas hosts and manages -your MongoDB database in the cloud. - -.. procedure:: - :style: connected - - .. step:: Create a free MongoDB deployment on Atlas - - Complete the :atlas:`Get Started with Atlas ` - guide to set up a new Atlas account and load sample data into a new free - tier MongoDB deployment. - - .. step:: Save your credentials - - After you create your database user, save that user's - username and password to a safe location for use in an upcoming step. - -After you complete these steps, you have a new free tier MongoDB -deployment on Atlas, database user credentials, and sample data loaded -in your database. - -.. include:: /includes/get-started/troubleshoot.rst \ No newline at end of file diff --git a/source/get-started/download-and-install.txt b/source/get-started/download-and-install.txt deleted file mode 100644 index 18090fb6..00000000 --- a/source/get-started/download-and-install.txt +++ /dev/null @@ -1,62 +0,0 @@ -.. _ruby-quick-start-download-and-install: - -==================== -Download and Install -==================== - -.. facet:: - :name: genre - :values: tutorial - -.. meta:: - :keywords: installation, setup, code example - -.. procedure:: - :style: connected - - .. step:: Install dependencies - - Before you begin developing, ensure you install `Ruby - `__ version 2.7 - or later in your development environment. {+language+} - is pre-installed on macOS and some Linux distributions, - but you might need to update your version. - - .. important:: - - The {+driver-short+} is not officially supported on Windows. - - .. step:: Create a project directory - - Run the following command in your shell to create a directory - called ``ruby-quickstart`` for this project: - - .. code-block:: bash - - mkdir ruby-quickstart - - Then, run the following commands to create a ``quickstart.rb`` file in - the ``ruby-quickstart`` directory: - - .. code-block:: bash - - cd ruby-quickstart - touch quickstart.rb - - .. step:: Add the {+driver-short+} to your project - - Open the ``quickstart.rb`` file and add the following code: - - .. literalinclude:: /includes/get-started/quickstart.rb - :language: ruby - :dedent: - :start-after: start-bundler - :end-before: end-bundler - - This code adds the {+driver-short+} as a dependency by - using the `Bundler `__ dependency management tool. - -After you complete these steps, you have a new project directory with the driver -dependencies installed. - -.. include:: /includes/get-started/troubleshoot.rst diff --git a/source/get-started/next-steps.txt b/source/get-started/next-steps.txt deleted file mode 100644 index f47a193b..00000000 --- a/source/get-started/next-steps.txt +++ /dev/null @@ -1,23 +0,0 @@ -.. _ruby-get-started-next-steps: - -========== -Next Steps -========== - -.. facet:: - :name: genre - :values: reference - -.. meta:: - :keywords: learn more - -Congratulations on completing the quick start tutorial! - -In this tutorial, you created a {+language+} application that -connects to a MongoDB deployment hosted on MongoDB Atlas -and retrieves a document that matches a query. - -Learn more about the {+driver-short+} from the following resources: - -- Learn how to perform read operations in the :ref:`` section. -- Learn how to perform write operations in the :ref:`` section. \ No newline at end of file diff --git a/source/includes/get-started/troubleshoot.rst b/source/includes/get-started/troubleshoot.rst index 6860d7be..fdabbf7e 100644 --- a/source/includes/get-started/troubleshoot.rst +++ b/source/includes/get-started/troubleshoot.rst @@ -1,6 +1,6 @@ .. note:: - If you run into issues on this step, ask for help in the + If you run into issues getting started, ask for help in the :community-forum:`MongoDB Community Forums ` or submit feedback by using the :guilabel:`Rate this page` tab on the right side of this page. \ No newline at end of file diff --git a/source/index.txt b/source/index.txt index f237301f..0619af58 100644 --- a/source/index.txt +++ b/source/index.txt @@ -17,20 +17,18 @@ Get Started Connect - Databases & Collections - Read Data - Write Data - Operations on Replica Sets + CRUD Operations + Aggregation + Data Formats Indexes - Monitor Your Application - Data Aggregation - {+avs+} + Run a Database Command + Atlas Search + Atlas Vector Search + Logging and Monitoring Security - Data Formats - API Documentation <{+api-root+}> Reference + API Documentation <{+api-root+}> Issues & Help - Common Errors Introduction ------------ diff --git a/source/logging-and-monitoring.txt b/source/logging-and-monitoring.txt new file mode 100644 index 00000000..8a2b57ab --- /dev/null +++ b/source/logging-and-monitoring.txt @@ -0,0 +1,13 @@ +.. _ruby-logging-monitoring + +====================== +Logging and Monitoring +====================== + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + Logging + Monitoring + Change Streams diff --git a/source/read/change-streams.txt b/source/logging-and-monitoring/change-streams.txt similarity index 100% rename from source/read/change-streams.txt rename to source/logging-and-monitoring/change-streams.txt diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt new file mode 100644 index 00000000..dfeac0c6 --- /dev/null +++ b/source/logging-and-monitoring/logging.txt @@ -0,0 +1,5 @@ +.. _ruby-logging: + +======== +Logging +======== diff --git a/source/monitoring/cluster-monitoring.txt b/source/logging-and-monitoring/monitoring.txt similarity index 99% rename from source/monitoring/cluster-monitoring.txt rename to source/logging-and-monitoring/monitoring.txt index c30dcd7c..9650ca3d 100644 --- a/source/monitoring/cluster-monitoring.txt +++ b/source/logging-and-monitoring/monitoring.txt @@ -1,8 +1,8 @@ .. _ruby-cluster-monitoring: -================== -Cluster Monitoring -================== +========== +Monitoring +========== .. facet:: :name: genre diff --git a/source/reference.txt b/source/reference.txt index 0129ab17..0b9e3059 100644 --- a/source/reference.txt +++ b/source/reference.txt @@ -12,8 +12,8 @@ Reference :maxdepth: 1 Release Notes - Upgrade Versions Compatibility + Upgrade Versions View the Source - :ref:`Release Notes ` diff --git a/source/databases-collections/run-command.txt b/source/run-command.txt similarity index 100% rename from source/databases-collections/run-command.txt rename to source/run-command.txt diff --git a/source/security.txt b/source/security.txt index d1d745f6..1709a513 100644 --- a/source/security.txt +++ b/source/security.txt @@ -20,5 +20,6 @@ Security .. toctree:: :titlesonly: + TLS Authentication In-Use Encryption \ No newline at end of file diff --git a/source/connect/tls.txt b/source/security/tls.txt similarity index 100% rename from source/connect/tls.txt rename to source/security/tls.txt diff --git a/source/vector-search.txt b/source/vector-search.txt index 593783f7..ab9e670f 100644 --- a/source/vector-search.txt +++ b/source/vector-search.txt @@ -1,8 +1,8 @@ .. _ruby-atlas-vector-search: -================================ -Run an {+avs+} Query -================================ +=================== +Atlas Vector Search +=================== .. facet:: :name: genre