Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
ef3bba89
Commit
ef3bba89
authored
Nov 16, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DOCS-8719: MongoDB\Client example for SSL and auth
parent
63952aa1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
MongoDBClient__construct.txt
docs/reference/method/MongoDBClient__construct.txt
+45
-0
No files found.
docs/reference/method/MongoDBClient__construct.txt
View file @
ef3bba89
...
@@ -39,6 +39,9 @@ Errors/Exceptions
...
@@ -39,6 +39,9 @@ Errors/Exceptions
Examples
Examples
--------
--------
Connecting to a Replica Set
~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you do not specify a ``$uri`` value, the driver connects to a standalone
If you do not specify a ``$uri`` value, the driver connects to a standalone
:program:`mongod` on ``127.0.0.1`` via port ``27017``. The following example
:program:`mongod` on ``127.0.0.1`` via port ``27017``. The following example
demonstrates how to connect to a replica set with a custom read preference:
demonstrates how to connect to a replica set with a custom read preference:
...
@@ -54,6 +57,48 @@ demonstrates how to connect to a replica set with a custom read preference:
...
@@ -54,6 +57,48 @@ demonstrates how to connect to a replica set with a custom read preference:
]
]
);
);
Connecting with SSL and Authentication
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following example demonstrates how to connect to a MongoDB replica set with
SSL and authentication, as is used for `MongoDB Atlas
<https://cloud.mongodb.com/?jmp=docs>`_:
.. code-block:: php
<?php
$client = new MongoDB\Client(
'mongodb://myUsername:myPassword@rs1.example.com,rs2.example.com/?ssl=true&replicaSet=myReplicaSet&authSource=admin'
);
Alternatively, the authentication credentials and URI parameters may be
specified in the constructor's ``$uriOptions`` parameter:
.. code-block:: php
<?php
$client = new MongoDB\Client(
'mongodb://rs1.example.com,rs2.example.com/'
[
'username' => 'myUsername',
'password' => 'myPassword',
'ssl' => true,
'replicaSet' => 'myReplicaSet',
'authSource' => 'admin',
],
);
The driver supports additional :php:`SSL options
<mongodb-driver-manager.construct#mongodb-driver-manager.construct-driveroptions>`,
which may be specified in the constructor's ``$driverOptions`` parameter. Those
options are covered in the :php:`MongoDB\\Driver\\Manager::__construct()
<mongodb-driver-manager.construct>` documentation.
Specifying a Custom Type Map
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default, the |php-library| deserializes BSON documents and arrays
By default, the |php-library| deserializes BSON documents and arrays
as :phpclass:`MongoDB\\Model\\BSONDocument` and
as :phpclass:`MongoDB\\Model\\BSONDocument` and
:phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following
:phpclass:`MongoDB\\Model\\BSONArray` objects, respectively. The following
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment