-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41957 - Mongo Client #106
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
Changes from 2 commits
5bec025
39512e4
d5e4422
e02bfd7
60bac62
a1597a8
8ba01bf
915d272
2948915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,110 @@ | ||||||
.. _php-client: | ||||||
|
||||||
======================= | ||||||
Create a MongoDB Client | ||||||
======================= | ||||||
|
||||||
.. facet:: | ||||||
:name: genre | ||||||
:values: reference | ||||||
|
||||||
.. meta:: | ||||||
:keywords: connection string, URI, server, Atlas, settings | ||||||
|
||||||
.. contents:: On this page | ||||||
:local: | ||||||
:backlinks: none | ||||||
:depth: 2 | ||||||
:class: singlecol | ||||||
|
||||||
Overview | ||||||
-------- | ||||||
|
||||||
To connect to a MongoDB deployment, you need two things: | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
- A **connection URI**, also known as a *connection string*, which tells the {+driver-short+} | ||||||
which MongoDB deployment to connect to. | ||||||
- A **MongoDB\\Client** object, which creates the connection to the MongoDB deployment | ||||||
and lets you perform operations on it. | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
You can also use either of these components to customize the way the {+driver-short+} behaves | ||||||
while connected to MongoDB. | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
This guide shows you how to create a connection string and use a ``MongoDB\Client`` object | ||||||
to connect to MongoDB. | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
.. _php-connection-uri: | ||||||
|
||||||
Connection URI | ||||||
-------------- | ||||||
|
||||||
A standard connection string includes the following components: | ||||||
|
||||||
.. list-table:: | ||||||
:widths: 20 80 | ||||||
:header-rows: 1 | ||||||
|
||||||
* - Component | ||||||
- Description | ||||||
|
||||||
* - ``mongodb://`` | ||||||
|
||||||
- Required. A prefix that identifies this as a string in the | ||||||
standard connection format. | ||||||
|
||||||
* - ``username:password`` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. S: change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do these need to be disambiguated from other credentials? the following paragraph also says they're for the DB. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be either. Just figured we might start integrating those placeholders where applicable so that there are fewer mis-matches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered including that connection string image on this page and using those placeholders instead? another option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not opposed to this change, but should we be consistent with the Server manual? https://www.mongodb.com/docs/manual/reference/connection-string/#connection-string-components There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit late here, but I don't think these should be See also: connection string spec |
||||||
|
||||||
- Optional. Authentication credentials. If you include these, the client | ||||||
authenticates the user against the database specified in ``authSource``. | ||||||
For more information about the ``authSource`` connection option, see | ||||||
:ref:`php-auth`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. broken for now |
||||||
|
||||||
* - ``host[:port]`` | ||||||
|
||||||
- Required. The host and optional port number where MongoDB is running. If you don't | ||||||
include the port number, the driver uses the default port, ``27017``. | ||||||
|
||||||
* - ``/defaultauthdb`` | ||||||
|
||||||
- Optional. The authentication database to use if the | ||||||
connection string includes ``username:password@`` | ||||||
authentication credentials but not the ``authSource`` option. If you don't include | ||||||
this component, the client authenticates the user against the ``admin`` database. | ||||||
|
||||||
* - ``?<options>`` | ||||||
|
||||||
- Optional. A query string that specifies connection-specific | ||||||
options as ``<name>=<value>`` pairs. See | ||||||
:ref:`php-connection-options` for a full description of | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. broken for now |
||||||
these options. | ||||||
|
||||||
For more information about creating a connection string, see | ||||||
:manual:`Connection Strings </reference/connection-string>` in the | ||||||
MongoDB Server documentation. | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Create a ``MongoDB\Client`` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll follow the Style Guide, but this is a Bad Rule imo |
||||||
--------------------------- | ||||||
|
||||||
To create a connection to MongoDB, construct an instance of the ``MongoDB\Client`` class, | ||||||
passing the connection URI as a string to the constructor. | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
In the following example, the library uses a sample connection URI to connect to a MongoDB | ||||||
deployment on port ``27017`` of ``localhost``: | ||||||
|
||||||
.. literalinclude:: /includes/connect/client.php | ||||||
:language: php | ||||||
:copyable: true | ||||||
|
||||||
.. tip:: Reuse Your Client | ||||||
|
||||||
Because each ``MongoDB\Client`` object represents a pool of connections to the | ||||||
database, most applications require only a single instance of | ||||||
``MongoDB\Client``, even across multiple requests. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
API Documentation | ||||||
----------------- | ||||||
|
||||||
To learn more about creating a ``MongoDB\Client`` object in the {+driver-short+}, | ||||||
see the following API documentation: | ||||||
|
||||||
- :ref:`MongoDB\Client <php-api-mongodbclient>` | ||||||
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
mongoKart marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$client = new MongoDB\Client("mongodb://localhost:27017"); | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using "driver" so existing source constant references keep working. can rename all refs in a later PR if needed