2
2
3
3
require 'vendor/autoload.php ' ;
4
4
5
- use MongoDB \Client ;
6
-
7
5
// Connects to a local MongoDB deployment
8
6
// start-local
9
7
$ uri = 'mongodb://localhost:27017/ ' ;
10
- $ client = new Client ($ uri );
8
+ $ client = new MongoDB \ Client ($ uri );
11
9
// end-local
12
10
13
11
// Connects to a MongoDB Atlas deployment
14
12
// start-atlas
15
13
$ uri = '<Atlas connection string> ' ;
16
- $ client = new Client ($ uri );
14
+ $ client = new MongoDB \ Client ($ uri );
17
15
// end-atlas
18
16
19
17
// Connects to a replica set
20
18
// start-replica-set
21
19
$ uri = 'mongodb://<replica set member>:<port>/?replicaSet=<replica set name> ' ;
22
- $ client = new Client ($ uri );
20
+ $ client = new MongoDB \ Client ($ uri );
23
21
// end-replica-set
24
22
25
23
// Connects to a MongoDB deployment and enables TLS using client
26
24
// options
27
25
// start-enable-tls-client
28
- $ client = new Client (
26
+ $ client = new MongoDB \ Client (
29
27
'mongodb://<hostname>:<port>/ ' ,
30
28
['tls ' => true ],
31
29
);
35
33
// parameters
36
34
// start-enable-tls-uri
37
35
$ uri = 'mongodb://<hostname>:<port>/?tls=true ' ;
38
- $ client = new Client ($ uri );
36
+ $ client = new MongoDB \ Client ($ uri );
39
37
// end-enable-tls-uri
40
38
41
39
// Connects to a MongoDB deployment, enables TLS, and specifies the path to
42
40
// a CA file using client options
43
41
// start-ca-file-client
44
- $ client = new Client (
42
+ $ client = new MongoDB \ Client (
45
43
'mongodb://<hostname>:<port>/ ' ,
46
44
['tls ' => true , 'tlsCAFile ' => '/path/to/ca.pem ' ],
47
45
);
51
49
// a CA file using connection URI parameters
52
50
// start-ca-file-uri
53
51
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsCAFile=/path/to/ca.pem ' ;
54
- $ client = new Client ($ uri );
52
+ $ client = new MongoDB \ Client ($ uri );
55
53
// end-ca-file-uri
56
54
57
55
// Connects to a MongoDB deployment, enables TLS, and prevents OCSP endpoint checks
58
56
// using client options
59
57
// start-disable-ocsp-client
60
- $ client = new Client (
58
+ $ client = new MongoDB \ Client (
61
59
'mongodb://<hostname>:<port>/ ' ,
62
60
['tls ' => true , 'tlsDisableOCSPEndpointCheck ' => true ],
63
61
);
67
65
// using connection URI parameters
68
66
// start-disable-ocsp-uri
69
67
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsDisableOCSPEndpointCheck=true ' ;
70
- $ client = new Client ($ uri );
68
+ $ client = new MongoDB \ Client ($ uri );
71
69
// end-disable-ocsp-uri
72
70
73
71
// Connects to a TLS-enabled deployment and instructs the driver to check the
74
72
// server certificate against a CRL
75
73
// start-crl
76
- $ client = new Client (
74
+ $ client = new MongoDB \ Client (
77
75
'mongodb://<hostname>:<port>/ ' ,
78
76
['tls ' => true ],
79
77
['crl_file ' => '/path/to/file.pem ' ],
83
81
// Presents a client certificate to prove identity
84
82
// using client options
85
83
// start-client-cert-client
86
- $ client = new Client (
84
+ $ client = new MongoDB \ Client (
87
85
'mongodb://<hostname>:<port>/ ' ,
88
86
['tls ' => true , 'tlsCertificateKeyFile ' => '/path/to/client.pem ' ],
89
87
);
93
91
// using connection URI parameters
94
92
// start-client-cert-uri
95
93
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsCertificateKeyFile=/path/to/client.pem ' ;
96
- $ client = new Client ($ uri );
94
+ $ client = new MongoDB \ Client ($ uri );
97
95
// end-client-cert-uri
98
96
99
97
// Specifies the password for a client certificate using client options
100
98
// start-key-file-client
101
- $ client = new Client (
99
+ $ client = new MongoDB \ Client (
102
100
'mongodb://<hostname>:<port>/ ' ,
103
101
[
104
102
'tls ' => true ,
111
109
// Specifies the password for a client certificate using connection URI parameters
112
110
// start-key-file-uri
113
111
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsCertificateKeyFile=/path/to/client.pem&tlsCertificateKeyFilePassword=<password> ' ;
114
- $ client = new Client ($ uri );
112
+ $ client = new MongoDB \ Client ($ uri );
115
113
// end-key-file-uri
116
114
117
115
// Connects to a TLS-enabled deployment and disables server certificate verification
118
116
// using client options
119
117
// start-insecure-tls-client
120
- $ client = new Client (
118
+ $ client = new MongoDB \ Client (
121
119
'mongodb://<hostname>:<port>/ ' ,
122
120
['tls ' => true , 'tlsInsecure ' => true ],
123
121
);
127
125
// using connection URI parameters
128
126
// start-insecure-tls-uri
129
127
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsInsecure=true ' ;
130
- $ client = new Client ($ uri );
128
+ $ client = new MongoDB \ Client ($ uri );
131
129
// end-insecure-tls-uri
132
130
133
131
// Disables certificate validation using client options
134
132
// start-disable-cert-client
135
- $ client = new Client (
133
+ $ client = new MongoDB \ Client (
136
134
'mongodb://<hostname>:<port>/ ' ,
137
135
['tls ' => true , 'tlsAllowInvalidCertificates ' => true ],
138
136
);
141
139
// Disables certificate validation using connection URI parameters
142
140
// start-disable-cert-uri
143
141
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsAllowInvalidCertificates=true ' ;
144
- $ client = new Client ($ uri );
142
+ $ client = new MongoDB \ Client ($ uri );
145
143
// end-disable-cert-uri
146
144
147
145
// Connects to a TLS-enabled deployment and disables hostname verification
148
146
// using client options
149
147
// start-disable-hostname-client
150
- $ client = new Client (
148
+ $ client = new MongoDB \ Client (
151
149
'mongodb://<hostname>:<port>/ ' ,
152
150
['tls ' => true , 'tlsAllowInvalidHostnames ' => true ],
153
151
);
157
155
// using connection URI parameters
158
156
// start-disable-hostname-uri
159
157
$ uri = 'mongodb://<hostname>:<port>/?tls=true&tlsAllowInvalidHostnames=true ' ;
160
- $ client = new Client ($ uri );
158
+ $ client = new MongoDB \ Client ($ uri );
161
159
// end-disable-hostname-uri
162
160
163
161
// Connects to a MongoDB deployment and enables the stable API
164
162
// start-stable-api
165
- $ uri = '<connection string> ' ;
166
- $ clientOptions = [
167
- 'serverApi ' => [
168
- 'version ' => '1 ' ,
169
- ],
170
- ];
171
- $ client = new Client ($ uri , $ clientOptions );
163
+ $ driverOptions = ['serverApi ' => new MongoDB \Driver \ServerApi (ServerApi::V1 )];
164
+ $ client = new MongoDB \Client (
165
+ 'mongodb://<hostname>:<port>/ ' ,
166
+ [],
167
+ $ driverOptions ,
168
+ );
172
169
// end-stable-api
173
170
174
171
?>
0 commit comments