-
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
Merged
mongoKart
merged 9 commits into
mongodb:php-standardization
from
mongoKart:docsp-41957-mongo-client
Aug 27, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bec025
first draft
mongoKart 39512e4
fixes
mongoKart d5e4422
Apply suggestions from code review
mongoKart e02bfd7
Apply suggestions from code review
mongoKart 60bac62
feedback
mongoKart a1597a8
Apply suggestions from code review
mongoKart 8ba01bf
feedback
mongoKart 915d272
space
mongoKart 2948915
Merge branch 'php-standardization' into docsp-41957-mongo-client
mongoKart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
.. _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 must create the following items: | ||
|
||
- **Connection URI**, also known as a *connection string*, which tells the {+driver-short+} | ||
which MongoDB deployment to connect to. | ||
- **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 set options within either or both of these components to | ||
customize the way that the {+driver-short+} behaves | ||
while connected to MongoDB. | ||
|
||
This guide describes the components of a connection string and shows how to | ||
use a ``MongoDB\Client`` object to connect to a MongoDB deployment. | ||
|
||
.. _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. | ||
|
||
* - ``db_username:db_password`` | ||
|
||
- 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 ``db_username:db_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. | ||
|
||
To learn more about connection strings, see | ||
:manual:`Connection Strings </reference/connection-string>` in the | ||
Server manual. | ||
|
||
Create a MongoDB\Client | ||
----------------------- | ||
|
||
To create a connection to MongoDB, pass your connection string when constructing | ||
an instance of the ``MongoDB\Client`` class. | ||
|
||
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 | ||
|
||
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$client = new MongoDB\Client("mongodb://localhost:27017"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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