Skip to content

DOCSP-35938: Connection Guide docs #2881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 22, 2024

Conversation

ccho-mongodb
Copy link
Contributor

@ccho-mongodb ccho-mongodb commented Apr 18, 2024

JIRA: https://jira.mongodb.org/browse/DOCSP-35938

Staging:
Connection Guide

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@ccho-mongodb ccho-mongodb changed the title Docsp 35938 connect to mongodb DOCSP-35938: Connection Guide docs Apr 18, 2024

- ``maxPoolSize=20``
- ``w=majority``

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:
This section will include a link to the Connection Options page once completed.

@GromNaN GromNaN self-requested a review April 19, 2024 07:51

.. code-block:: bash

DB_URI="mongodb://myUser:myPass123@host1:27017,host2:27017,host3:27017/?replicaSet=myRS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After testing on a local replica set, I can confirm that the replicatSet option works.

MONGODB_URI="mongodb://localhost:27017,localhost:27018,localhost:27019/"
        'mongodb' => [
            'driver' => 'mongodb',
            'dsn' => env('MONGODB_URI'),
            'database' => 'laravel',
            'options' => [
                'replicaSet' => 'myRS',
            ]
        ]

You can also pass the list of hosts like this:

        'mongodb' => [
            'driver' => 'mongodb',
            'host' => [
                '127.0.0.1:27017',
                '127.0.0.1:27018',
                '127.0.0.1:27019',
            ],
            'database' => 'laravel',
            'options' => [
                'replicaSet' => 'myRS',
            ]
        ]

Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few things!

/fundamentals/database-collection
/fundamentals/read-operations
/fundamentals/write-operations

Learn how to use the {+odm-long+} to perform the following tasks:

- :ref:`Manage Databases and Collections <laravel-db-coll>`
- :ref:`Connections <laravel-fundamentals-connection>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: though Connections is the name of the page, perhaps this link text could be more matched to the intro phrase "perform the following tasks"

Suggested change
- :ref:`Connections <laravel-fundamentals-connection>`
- :ref:`Configure Your Connection to MongoDB <laravel-fundamentals-connection>`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add an item to the cleanup ticket to address the other titles that aren't action oriented.

/fundamentals/database-collection
/fundamentals/read-operations
/fundamentals/write-operations

Learn how to use the {+odm-long+} to perform the following tasks:

- :ref:`Manage Databases and Collections <laravel-db-coll>`
- :ref:`Connections <laravel-fundamentals-connection>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: also add this to the list of fundamentals pages on the index (alternatively, move into an include that is used on both pages)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the item to index.txt and then adding the task to move it into an include to the cleanup ticket since it impacts other content.

Comment on lines 20 to 22
Learn how to set up a connection and specify connection behavior from your
Laravel application to a MongoDB deployment by using {+odm-short+} in the
following sections:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Learn how to set up a connection and specify connection behavior from your
Laravel application to a MongoDB deployment by using {+odm-short+} in the
following sections:
Learn how to set up a connection from your Laravel application to a MongoDB
deployment and specify connection behavior by using {+odm-short+} in the
following sections:

Laravel application to a MongoDB deployment by using {+odm-short+} in the
following sections:

- :ref:`Connect to MongoDB <laravel-connect-to-mongodb>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why is this called connect to MongoDB instead of Connection Guide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a custom title with similar intent to the suggestions you made earlier. To keep it simple, I'd suggest that we only use the titles of the pages and then describe them as necessary. Let me know what you think and I'll add the appropriate task to the cleanup ticket.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a good solution to prevent the same page from being referred to by different things in different places!

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, added "Use the original titles for all landing page link lists. Use a description if it needs additional explanation." to the cleanup ticket.

Comment on lines 90 to 91
- ``default``, which specifies the default database connection to use when
unspecified
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ``default``, which specifies the default database connection to use when
unspecified
- ``default``, which specifies the default database connection to use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I wanted to emphasize the behavior of the default value, but now think maybe including "default" in the description of itself might be confusing. think maybe a more clear way to describe this could be:
"default, which specifies the database connection to use when unspecified"

Comment on lines 104 to 113
- ``driver``, which specifies the database driver to use for the connection
- ``dsn``, the data source name (DSN) that specifies the MongoDB connection URI
- ``host``, which you can use instead of the ``dsn`` setting to specify the
network address of one or more MongoDB nodes
- ``database``, which specifies the name of the MongoDB database to read and
write to
- ``username`` and ``password``, which you can optionally include to specify
your database user's credentials to authenticate with MongoDB
- ``options`` and ``driverOptions``, which specify connection options to
pass to the MongoDB driver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: maybe converting this into a table could be helpful

Comment on lines 112 to 113
- ``options`` and ``driverOptions``, which specify connection options to
pass to the MongoDB driver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: is there a place to find a complete list of what goes under each property? Or will this be covered in the connection options page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for asking. These are covered in the Connection Options ticket and a link will be added to this page per #2881 (comment)

To connect your application to a MongoDB instance hosted on the same machine,
you must complete the following tasks:

- Download, install, and run MongoDB server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Download, install, and run MongoDB server.
- Download, install, and run the MongoDB server.

Comment on lines 110 to 111
- ``username`` and ``password``, which you can optionally include to specify
your database user's credentials to authenticate with MongoDB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: right now, it's not very clear that using different properties such as host username password port, etc. is an alternative to including all of this information in the DSN

S: add an admonition or revise these descriptions to make this clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Will add an admonition to explain.

Copy link
Contributor

@rustagir rustagir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Laravel application to a MongoDB deployment by using {+odm-short+} in the
following sections:

- :ref:`Connect to MongoDB <laravel-connect-to-mongodb>`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a good solution to prevent the same page from being referred to by different things in different places!

one or more databases from your application

You can use the following code in the configuration file to set the default
connection to a corresponding ``"mongodb"`` entry in the ``connections`` array:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
connection to a corresponding ``"mongodb"`` entry in the ``connections`` array:
connection to a corresponding ``mongodb`` entry in the ``connections`` array:

.. code-block:: php
:caption: Sample .env environment configuration

DB_URI=""mongodb+srv://myUser:[email protected]/";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DB_URI=""mongodb+srv://myUser:[email protected]/";
DB_URI="mongodb+srv://myUser:[email protected]/"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, great catch!
I should also use "bash" instead of "php" highlighting.

@ccho-mongodb ccho-mongodb marked this pull request as ready for review April 19, 2024 20:35
@ccho-mongodb ccho-mongodb requested a review from a team as a code owner April 19, 2024 20:35
@ccho-mongodb ccho-mongodb requested a review from GromNaN April 19, 2024 20:35
Comment on lines 116 to 118
* - ``host``
- Specifies the network address of one or more MongoDB nodes in a
deployment. You can use this setting instead of the ``dsn`` setting.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is host:port or a list of host:port.

Examples:

  • 'host' => 'localhost:27017'
  • 'host' => ['server1.example.net:27017', 'server2.example.net:27017', 'server3.example.net:27017']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: from my experimentation, this option only accepts non-seedlist hostnames (mongodb and not mongodb+srv), correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, we need to add an option for mongodb+srv.

return 'mongodb://' . implode(',', $hosts) . ($authDatabase ? '/' . $authDatabase : '');

Comment on lines +131 to +137
* - ``options``
- Specifies connection options to pass to MongoDB that determine the
connection behavior.

* - ``driverOptions``
- Specifies options specific to pass to the MongoDB PHP Library driver
that determine the driver behavior for that connection.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@ccho-mongodb ccho-mongodb Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will add links from options and driverOptions to the Connection Options page (which includes the link you provided) once merged as a cleanup task.

@ccho-mongodb ccho-mongodb requested a review from GromNaN April 22, 2024 16:36
@ccho-mongodb ccho-mongodb merged commit 19bb87f into mongodb:4.1 Apr 22, 2024
@ccho-mongodb ccho-mongodb deleted the DOCSP-35938-connect-to-mongodb branch April 22, 2024 17:18
This was referenced Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants