forked from mongodb/docs-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMongoDBDatabase-withOptions.txt
96 lines (67 loc) · 2.38 KB
/
MongoDBDatabase-withOptions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
================================
MongoDB\\Database::withOptions()
================================
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\Database::withOptions()
Returns a clone of the Database object, but with different options.
.. code-block:: php
function withOptions(array $options = []): MongoDB\Database
Parameters
----------
``$options`` : array
An array specifying the desired options.
.. list-table::
:header-rows: 1
:widths: 20 20 80
* - Name
- Type
- Description
* - builderEncoder
- ``MongoDB\Codec\Encoder``
- The encoder used to serialize native PHP types to BSON data in
query and aggregation options. If omitted, the ``Database``
instance uses the default encoder.
.. versionadded:: 1.21
* - readConcern
- :php:`MongoDB\Driver\ReadConcern <class.mongodb-driver-readconcern>`
- The default read concern to use for database operations. Defaults to
the original database's read concern.
* - readPreference
- :php:`MongoDB\Driver\ReadPreference <class.mongodb-driver-readpreference>`
- The default read preference to use for database operations. Defaults to
the original database's read preference.
* - typeMap
- array
- The :php:`type map
<manual/en/mongodb.persistence.deserialization.php#mongodb.persistence.typemaps>`
to apply to cursors, which determines how BSON documents are converted
to PHP values. Defaults to the original database's type map.
* - writeConcern
- :php:`MongoDB\Driver\WriteConcern <class.mongodb-driver-writeconcern>`
- The default write concern to use for database operations. Defaults to
the original database's write concern.
Return Values
-------------
A :phpclass:`MongoDB\Database` object.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
Example
-------
The following example clones an existing Database object with a new read
preference:
.. code-block:: php
<?php
$db = (new MongoDB\Client)->test;
$newDb = $db->withOptions([
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
]);
See Also
--------
- :phpmethod:`MongoDB\Database::__construct()`