Skip to content

Commit 5986fa9

Browse files
author
Joe Bennett
committed
#27345 new Lock\MongoDbStore construction options
1 parent 13bddeb commit 5986fa9

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

components/lock.rst

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -293,29 +293,51 @@ The MongoDbStore saves locks on a MongoDB server ``>=2.2``, it requires a
293293
This store does not support blocking and expects a TTL to
294294
avoid stalled locks::
295295

296-
use MongoDB\Client;
297296
use Symfony\Component\Lock\Store\MongoDbStore;
298297

299-
$client = new Client('mongo://localhost/');
300-
298+
$mongo = 'mongodb://localhost/database?collection=lock';
301299
$options = [
302-
'database' => 'my-app',
300+
'gcProbablity' => 0.001,
301+
'database' => 'myapp',
303302
'collection' => 'lock',
303+
'uriOptions' => [],
304+
'driverOptions' => [],
304305
];
306+
$store = new MongoDbStore($mongo, $options);
307+
308+
The ``MongoDbStore`` takes the following ``$options`` (depending on the first parameter type):
309+
310+
============= ================================================================================================
311+
Option Description
312+
============= ================================================================================================
313+
gcProbablity Should a TTL Index be created expressed as a probability from 0.0 to 1.0 (Defaults to ``0.001``)
314+
database The name of the database
315+
collection The name of the collection
316+
uriOptions Array of uri options for `MongoDBClient::__construct`_
317+
driverOptions Array of driver options for `MongoDBClient::__construct`_
318+
============= ================================================================================================
319+
320+
When the first parameter is a:
321+
322+
``MongoDB\Collection``:
305323

306-
$store = new MongoDbStore($client, $options);
324+
- ``$options['database']`` is ignored
325+
- ``$options['collection']`` is ignored
307326

308-
The ``MongoDbStore`` takes the following options (depending on the first parameter type):
327+
``MongoDB\Client``:
328+
329+
- ``$options['database']`` is mandatory
330+
- ``$options['collection']`` is mandatory
331+
332+
`MongoDB Connection String`_:
333+
334+
- ``/path`` is used otherwise ``$options['database']``, at least one is mandatory
335+
- ``?collection=`` is used otherwise ``$options['collection']``, at least one is mandatory
336+
337+
.. note::
309338

310-
============= ================================= ========= ========================================================================
311-
Option First Parameter Type Default Description
312-
============= ================================= ========= ========================================================================
313-
gcProbablity any ``0.001`` Should a TTL Index be created expressed as a probability from 0.0 to 1.0
314-
database ``\MongoDB\Client`` or ``string`` The name of the database [Mandatory]
315-
collection ``\MongoDB\Client`` or ``string`` ``lock`` The name of the collection
316-
uriOptions ``string`` ``[]`` Array of uri options for `MongoDBClient::__construct`_
317-
driverOptions ``string`` ``[]`` Array of driver options for `MongoDBClient::__construct`_
318-
============= ================================= ========= ========================================================================
339+
The ``collection`` querystring parameter is not part of the `MongoDB Connection String`_ definition.
340+
It is simply used to allow constructing a ``MongoDbStore`` using a `Data Source Name (DSN)`_ without ``$options``.
319341

320342
.. _lock-store-pdo:
321343

0 commit comments

Comments
 (0)