1MONGOC_URI_T(3)                    libmongoc                   MONGOC_URI_T(3)
2
3
4

NAME

6       mongoc_uri_t - mongoc_uri_t
7

SYNOPSIS

9          typedef struct _mongoc_uri_t mongoc_uri_t;
10

DESCRIPTION

12       mongoc_uri_t  provides  an abstraction on top of the MongoDB connection
13       URI format. It provides standardized parsing  as  well  as  convenience
14       methods  for  extracting  useful  information  such as replica hosts or
15       authorization information.
16
17       See Connection String URI Reference on the  MongoDB  website  for  more
18       information.
19

FORMAT

21          mongodb[+srv]://                             <1>
22             [username:password@]                      <2>
23             host1                                     <3>
24             [:port1]                                  <4>
25             [,host2[:port2],...[,hostN[:portN]]]      <5>
26             [/[database]                              <6>
27             [?options]]                               <7>
28
29       1. "mongodb"  is  the  specifier  of  the  MongoDB  protocol. Use "mon‐
30          godb+srv" with a single service name in place of "host1" to  specify
31          the initial list of servers with an SRV record.
32
33       2. An optional username and password.
34
35       3. The  only  required  part of the uri.  This specifies either a host‐
36          name, IPv4 address, IPv6 address enclosed in "[" and  "]",  or  UNIX
37          domain socket.
38
39       4. An optional port number.  Defaults to :27017.
40
41       5. Extra  optional  hosts and ports.  You would specify multiple hosts,
42          for example, for connections to replica sets.
43
44       6. The name of the database to authenticate if  the  connection  string
45          includes  authentication credentials.  If /database is not specified
46          and the connection string  includes  credentials,  defaults  to  the
47          'admin' database.
48
49       7. Connection specific options.
50
51       NOTE:
52          Option  names  are  case-insensitive.  Do not repeat the same option
53          (e.g. "mongodb://localhost/db?opt=value1&OPT=value2") since this may
54          have unexpected results.
55
56       The  MongoDB  C  Driver exposes constants for each supported connection
57       option. These constants make it easier to discover connection  options,
58       but their string values can be used as well.
59
60       For example, the following calls are equal.
61
62          uri = mongoc_uri_new ("mongodb://localhost/?" MONGOC_URI_APPNAME "=applicationName");
63          uri = mongoc_uri_new ("mongodb://localhost/?appname=applicationName");
64          uri = mongoc_uri_new ("mongodb://localhost/?appName=applicationName");
65

REPLICA SET EXAMPLE

67       To describe a connection to a replica set named 'test' with the follow‐
68       ing mongod hosts:
69
70       · db1.example.com on port 27017
71
72       · db2.example.com on port 2500
73
74       You would use a connection string that resembles the following.
75
76          mongodb://db1.example.com,db2.example.com:2500/?replicaSet=test
77

SRV EXAMPLE

79       If  you  have  configured  an  SRV  record  with  a  name  like  "_mon‐
80       godb._tcp.server.example.com"  whose  records are a list of one or more
81       MongoDB server hostnames, use a connection string like this:
82
83          uri = mongoc_uri_new ("mongodb+srv://server.example.com/?replicaSet=rs&appName=applicationName");
84
85       The driver prefixes the service name with "_mongodb._tcp.",  then  per‐
86       forms  a DNS SRV query to resolve the service name to one or more host‐
87       names. If this query succeeds, the driver performs a DNS TXT  query  on
88       the  service  name  (without the "_mongodb._tcp" prefix) for additional
89       URI options configured as TXT records.
90
91       On Unix, the MongoDB C Driver relies on libresolv to look  up  SRV  and
92       TXT  records.  If  libresolv is unavailable, then using a "mongodb+srv"
93       URI will cause an error. If your libresolv lacks res_nsearch  then  the
94       driver will fall back to res_search, which is not thread-safe.
95

IPV4 AND IPV6

97       If  connecting  to  a hostname that has both IPv4 and IPv6 DNS records,
98       the behavior follows RFC-6555. A connection  to  the  IPv6  address  is
99       attempted  first.  If IPv6 fails, then a connection is attempted to the
100       IPv4 address. If the connection  attempt  to  IPv6  does  not  complete
101       within  250ms,  then IPv4 is tried in parallel. Whichever succeeds con‐
102       nection first cancels the other. The successful DNS  result  is  cached
103       for 10 minutes.
104
105       As  a  consequence,  attempts  to connect to a mongod only listening on
106       IPv4 may be delayed if there are both A  (IPv4)  and  AAAA  (IPv6)  DNS
107       records associated with the host.
108
109       To  avoid  a delay, configure hostnames to match the MongoDB configura‐
110       tion. That is, only create an A record if the mongod is only  listening
111       on IPv4.
112

CONNECTION OPTIONS

114      ┌────────────────────┬──────────────────┬────────────────────────────────┐
115      │Constant            │ Key              │ Description                    │
116      ├────────────────────┼──────────────────┼────────────────────────────────┤
117      │MON‐                │ retryreads       │ If "true"  and  the            │
118      │GOC_URI_RETRYREADS  │                  │ server is a MongoDB            │
119      │                    │                  │ 3.6+    standalone,            │
120      │                    │                  │ replica   set,   or            │
121      │                    │                  │ sharded    cluster,            │
122      │                    │                  │ the  driver  safely            │
123      │                    │                  │ retries a read that            │
124      │                    │                  │ failed   due  to  a            │
125      │                    │                  │ network  error   or            │
126      │                    │                  │ replica         set            │
127      │                    │                  │ failover.                      │
128      └────────────────────┴──────────────────┴────────────────────────────────┘
129
130
131
132
133
134
135
136
137      │MONGOC_URI_RETRY‐   │ retrywrites      │ If  "true"  and the            │
138      │WRITES              │                  │ server is a MongoDB            │
139      │                    │                  │ 3.6+ replica set or            │
140      │                    │                  │ sharded    cluster,            │
141      │                    │                  │ the  driver  safely            │
142      │                    │                  │ retries   a   write            │
143      │                    │                  │ that  failed due to            │
144      │                    │                  │ a network error  or            │
145      │                    │                  │ replica         set            │
146      │                    │                  │ failover.      Only            │
147      │                    │                  │ inserts, updates of            │
148      │                    │                  │ single   documents,            │
149      │                    │                  │ or  deletes of sin‐            │
150      │                    │                  │ gle  documents  are            │
151      │                    │                  │ retried.                       │
152      ├────────────────────┼──────────────────┼────────────────────────────────┤
153      │MONGOC_URI_APPNAME  │ appname          │ The client applica‐            │
154      │                    │                  │ tion   name.   This            │
155      │                    │                  │ value  is  used  by            │
156      │                    │                  │ MongoDB   when   it            │
157      │                    │                  │ logs     connection            │
158      │                    │                  │ information     and            │
159      │                    │                  │ profile    informa‐            │
160      │                    │                  │ tion, such as  slow            │
161      │                    │                  │ queries.                       │
162      ├────────────────────┼──────────────────┼────────────────────────────────┤
163      │MONGOC_URI_TLS      │ tls              │ {true|false}, indi‐            │
164      │                    │                  │ cating if TLS  must            │
165      │                    │                  │ be  used. (See also            │
166      │                    │                  │ mon‐                           
167      │                    │                  │ goc_client_set_ssl_opts        
168      │                    │                  │ and            mon‐            
169      │                    │                  │ goc_client_pool_set_ssl_opts.) │
170      ├────────────────────┼──────────────────┼────────────────────────────────┤
171      │MONGOC_URI_COMPRES‐ │ compressors      │ Comma  separated  list of com‐ │
172      │SORS                │                  │ pressors, if any,  to  use  to │
173      │                    │                  │ compress   the  wire  protocol │
174      │                    │                  │ messages.  Snappy,  zlib,  and │
175      │                    │                  │ zstd  are  optional build time │
176      │                    │                  │ dependencies, and  enable  the │
177      │                    │                  │ "snappy",  "zlib",  and "zstd" │
178      │                    │                  │ values respectively.  Defaults │
179      │                    │                  │ to empty (no compressors).     │
180      ├────────────────────┼──────────────────┼────────────────────────────────┤
181      │MONGOC_URI_CONNECT‐ │ connecttimeoutms │ This setting  applies  to  new │
182      │TIMEOUTMS           │                  │ server connections. It is also │
183      │                    │                  │ used as the socket timeout for │
184      │                    │                  │ server  discovery and monitor‐ │
185      │                    │                  │ ing operations. The default is │
186      │                    │                  │ 10,000 ms (10 seconds).        │
187      ├────────────────────┼──────────────────┼────────────────────────────────┤
188      │MONGOC_URI_SOCKET‐  │ sockettimeoutms  │ The time  in  milliseconds  to │
189      │TIMEOUTMS           │                  │ attempt  to send or receive on │
190      │                    │                  │ a socket  before  the  attempt │
191      │                    │                  │ times   out.  The  default  is │
192      │                    │                  │ 300,000 (5 minutes).           │
193      ├────────────────────┼──────────────────┼────────────────────────────────┤
194      │MONGOC_URI_REPLI‐   │ replicaset       │ The  name  of  the Replica Set │
195      │CASET               │                  │ that the driver should connect │
196      │                    │                  │ to.                            │
197      └────────────────────┴──────────────────┴────────────────────────────────┘
198
199
200
201
202
203
204
205      │MONGOC_URI_ZLIBCOM‐ │ zlibcompression‐ │ When  the  MONGOC_URI_COMPRES‐ │
206      │PRESSIONLEVEL       │ level            │ SORS  includes   "zlib"   this │
207      │                    │                  │ options  configures  the  zlib │
208      │                    │                  │ compression  level,  when  the │
209      │                    │                  │ zlib  compressor  is  used  to │
210      │                    │                  │ compress client data.          │
211      └────────────────────┴──────────────────┴────────────────────────────────┘
212
213       Setting any of the *timeoutMS options above to 0 will be interpreted as
214       "use the default value".
215

AUTHENTICATION OPTIONS

217        ┌────────────────────┬────────────────────┬─────────────────────────┐
218        │Constant            │ Key                │ Description             │
219        ├────────────────────┼────────────────────┼─────────────────────────┤
220        │MONGOC_URI_AUTH‐    │ authmechanism      │ Specifies the mech‐     │
221        │MECHANISM           │                    │ anism  to  use when     │
222        │                    │                    │ authenticating   as     │
223        │                    │                    │ the  provided user.     │
224        │                    │                    │ See  Authentication     │
225        │                    │                    │ for  supported val‐     │
226        │                    │                    │ ues.                    │
227        ├────────────────────┼────────────────────┼─────────────────────────┤
228        │MONGOC_URI_AUTH‐    │ authmechanismprop‐ │ Certain authentica‐     │
229        │MECHANISMPROPERTIES │ erties             │ tion     mechanisms     │
230        │                    │                    │ have     additional     │
231        │                    │                    │ options that can be     │
232        │                    │                    │ configured.   These     │
233        │                    │                    │ options  should  be     │
234        │                    │                    │ provided  as  comma     │
235        │                    │                    │ separated               │
236        │                    │                    │ option_key:option_value │
237        │                    │                    │ pair  and  provided     │
238        │                    │                    │ as   authMechanism‐     │
239        │                    │                    │ Properties.             │
240        ├────────────────────┼────────────────────┼─────────────────────────┤
241        │MONGOC_URI_AUTH‐    │ authsource         │ The authSource  defines │
242        │SOURCE              │                    │ the    database    that │
243        │                    │                    │ should   be   used   to │
244        │                    │                    │ authenticate  to. It is │
245        │                    │                    │ unnecessary to  provide │
246        │                    │                    │ this  option  the data‐ │
247        │                    │                    │ base name is  the  same │
248        │                    │                    │ as the database used in │
249        │                    │                    │ the URI.                │
250        └────────────────────┴────────────────────┴─────────────────────────┘
251
252   Mechanism Properties
253           ┌────────────────────┬───────────────────┬─────────────────────┐
254           │Constant            │ Key               │ Description         │
255           ├────────────────────┼───────────────────┼─────────────────────┤
256           │MONGOC_URI_CANONI‐  │ canonicalizehost‐ │ Use  the  canonical │
257           │CALIZEHOSTNAME      │ name              │ hostname   of   the │
258           │                    │                   │ service,     rather │
259           │                    │                   │ than its configured │
260           │                    │                   │ alias, when authen‐ │
261           │                    │                   │ ticating       with │
262           │                    │                   │ Cyrus-SASL     Ker‐ │
263           │                    │                   │ beros.              │
264           ├────────────────────┼───────────────────┼─────────────────────┤
265           │MONGOC_URI_GSSAPIS‐ │ gssapiservicename │ Use     alternative │
266           │ERVICENAME          │                   │ service  name.  The │
267           │                    │                   │ default is mongodb. │
268           └────────────────────┴───────────────────┴─────────────────────┘
269

TLS OPTIONS

271          ──────────────────────────────────────────────────────────────────
272           Constant              Key                   Description
273          ──────────────────────────────────────────────────────────────────
274           MONGOC_URI_TLS        tls                   {true|false}, indi‐
275                                                       cating  if TLS must
276                                                       be used.
277          ──────────────────────────────────────────────────────────────────
278           MONGOC_URI_TLSCER‐    tlscertificatekey‐    Path to PEM format‐
279           TIFICATEKEYFILE       file                  ted   Private  Key,
280                                                       with   its   Public
281                                                       Certificate    con‐
282                                                       catenated  at   the
283                                                       end.
284          ──────────────────────────────────────────────────────────────────
285           MONGOC_URI_TLSCER‐    tlscertificatekey‐    The   password,  if
286           TIFICATEKEYPASSWORD   password              any,  to   use   to
287                                                       unlock    encrypted
288                                                       Private Key.
289          ──────────────────────────────────────────────────────────────────
290           MON‐                  tlscafile             One,  or  a  bundle
291           GOC_URI_TLSCAFILE                           of,     Certificate
292                                                       Authorities    whom
293                                                       should  be  consid‐
294                                                       ered to be trusted.
295          ──────────────────────────────────────────────────────────────────
296           MONGOC_URI_TLSAL‐     tlsallowinvalidcer‐   Accept  and  ignore
297           LOWINVALIDCERTIFI‐    tificates             certificate verifi‐
298           CATES                                       cation errors (e.g.
299                                                       untrusted   issuer,
300                                                       expired, etc.)
301          ──────────────────────────────────────────────────────────────────
302           MONGOC_URI_TLSAL‐     tlsallowinvalid‐      Ignore     hostname
303           LOWINVALIDHOSTNAMES   hostnames             verification of the
304                                                       certificate   (e.g.
305                                                       Man  In The Middle,
306                                                       using  valid   cer‐
307                                                       tificate,       but
308                                                       issued for  another
309                                                       hostname)
310          ──────────────────────────────────────────────────────────────────
311           MONGOC_URI_TLSINSE‐   tlsinsecure           {true|false}, indi‐
312           CURE                                        cating  if insecure
313                                                       TLS options  should
314                                                       be  used. Currently
315                                                       this  implies  MON‐
316                                                       GOC_URI_TLSALLOWIN‐
317                                                       VALIDCERTIFICATES
318                                                       and            MON‐
319                                                       GOC_URI_TLSALLOWIN‐
320                                                       VALIDHOSTNAMES.
321          ──────────────────────────────────────────────────────────────────
322           MONGOC_URI_TLSDIS‐    tlsdisablecertifi‐    {true|false}, indi‐
323           ABLECERTIFICATERE‐    caterevocationcheck   cates if revocation
324           VOCATIONCHECK                               checking   (CRL   /
325                                                       OCSP)   should   be
326                                                       disabled.
327          ──────────────────────────────────────────────────────────────────
328           MONGOC_URI_TLSDIS‐    tlsdisableocspend‐    {true|false}, indi‐
329           ABLEOCSPEND‐          pointcheck            cates    if    OCSP
330           POINTCHECK                                  responder endpoints
331                                                       should    not    be
332                                                       requested  when  an
333                                                       OCSP  response   is
334                                                       not stapled.
335          ┌────────────────────┬─────────────────────┬─────────────────────┐
336          │                    │                     │                     │
337       See│ configuring_tls for│details about these o│ptions and about build│ing
338       lib│mongoc with TLS suppo│rt.                   │                     │
339          │                    │                     │                     │

DEPRECATED SSL OPTIONS

341       The following options have been deprecated  and  may  be  removed  from
342       future releases of libmongoc.
343
344  ┌──────────────────────┬──────────────────┬───────────────────┬──────────────────┐
345  │Constant              │ Key              │ Deprecated For    │ Key              │
346  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
347  │MONGOC_URI_SSL        │ ssl              │ MONGOC_URI_TLS    │ tls              │
348  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
349  │MON‐                  │ sslclientcer‐    │ MON‐              │ tlscertifi‐      │
350  │GOC_URI_SSLCLIENTCER‐ │ tificatekeyfile  │ GOC_URI_TLSCER‐   │ catekeyfile      │
351  │TIFICATEKEYFILE       │                  │ TIFICATEKEYFILE   │                  │
352  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
353  │MON‐                  │ sslclientcer‐    │ MON‐              │ tlscertifi‐      │
354  │GOC_URI_SSLCLIENTCER‐ │ tificatekeypass‐ │ GOC_URI_TLSCER‐   │ catekeypassword  │
355  │TIFICATEKEYPASSWORD   │ word             │ TIFICATEKEYPASS‐  │                  │
356  │                      │                  │ WORD              │                  │
357  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
358  │MONGOC_URI_SSLCER‐    │ sslcertifi‐      │ MON‐              │ tlscafile        │
359  │TIFICATEAUTHORITYFILE │ cateauthority‐   │ GOC_URI_TLSCAFILE │                  │
360  │                      │ file             │                   │                  │
361  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
362  │MONGOC_URI_SSLALLOW‐  │ sslallowinvalid‐ │ MONGOC_URI_TLSAL‐ │ tlsallowinvalid‐ │
363  │INVALIDCERTIFICATES   │ certificates     │ LOWINVALIDCER‐    │ certificates     │
364  │                      │                  │ TIFICATES         │                  │
365  ├──────────────────────┼──────────────────┼───────────────────┼──────────────────┤
366  │MONGOC_URI_SSLALLOW‐  │ sslallowinvalid‐ │ MONGOC_URI_TLSAL‐ │ tlsallowinvalid‐ │
367  │INVALIDHOSTNAMES      │ hostnames        │ LOWINVALIDHOST‐   │ hostnames        │
368  │                      │                  │ NAMES             │                  │
369  └──────────────────────┴──────────────────┴───────────────────┴──────────────────┘
370

SERVER DISCOVERY, MONITORING, AND SELECTION OPTIONS

372       Clients in a mongoc_client_pool_t share a topology scanner that runs on
373       a  background  thread.  The  thread  wakes  every  heartbeatFrequencyMS
374       (default 10 seconds) to scan all MongoDB servers in parallel.  Whenever
375       an application operation requires a server that is not known--for exam‐
376       ple, if there is no known primary  and  your  application  attempts  an
377       insert--the thread rescans all servers every half-second. In this situ‐
378       ation the pooled client waits up to  serverSelectionTimeoutMS  (default
379       30 seconds) for the thread to find a server suitable for the operation,
380       then returns an error with domain MONGOC_ERROR_SERVER_SELECTION.
381
382       Technically, the total time an operation may wait while a pooled client
383       scans  the  topology is controlled both by serverSelectionTimeoutMS and
384       connectTimeoutMS. The longest wait occurs if the last scan begins  just
385       at the end of the selection timeout, and a slow or down server requires
386       the full connection timeout before the client gives up.
387
388       A non-pooled client is single-threaded. Every heartbeatFrequencyMS,  it
389       blocks  the  next  application operation while it does a parallel scan.
390       This scan takes as long as needed to check the slowest server:  roughly
391       connectTimeoutMS.  Therefore  the default heartbeatFrequencyMS for sin‐
392       gle-threaded clients is greater than for pooled clients: 60 seconds.
393
394       By default, single-threaded (non-pooled) clients scan only once when an
395       operation requires a server that is not known. If you attempt an insert
396       and there is no known primary, the client checks all servers once  try‐
397       ing  to  find  it,  then  succeeds or returns an error with domain MON‐
398       GOC_ERROR_SERVER_SELECTION. But if you  set  serverSelectionTryOnce  to
399       "false",  the  single-threaded client loops, checking all servers every
400       half-second, until serverSelectionTimeoutMS.
401
402       The total time an operation may wait for a  single-threaded  client  to
403       scan  the  topology  is  determined by connectTimeoutMS in the try-once
404       case, or serverSelectionTimeoutMS and connectTimeoutMS if  serverSelec‐
405       tionTryOnce is set "false".
406
407          ┌────────────────────┬─────────────────────┬─────────────────────┐
408          │Constant            │ Key                 │ Description         │
409          └────────────────────┴─────────────────────┴─────────────────────┘
410
411
412
413          │MONGOC_URI_HEART‐   │ heartbeatfrequen‐   │ The        interval │
414          │BEATFREQUENCYMS     │ cyms                │ between server mon‐ │
415          │                    │                     │ itoring     checks. │
416          │                    │                     │ Defaults         to │
417          │                    │                     │ 10,000ms  (10  sec‐ │
418          │                    │                     │ onds)   in   pooled │
419          │                    │                     │ (multi-threaded)    │
420          │                    │                     │ mode, 60,000ms  (60 │
421          │                    │                     │ seconds)         in │
422          │                    │                     │ non-pooled     mode │
423          │                    │                     │ (single-threaded).  │
424          ├────────────────────┼─────────────────────┼─────────────────────┤
425          │MONGOC_URI_SERVERS‐ │ serverselection‐    │ A  timeout  in mil‐ │
426          │ELECTIONTIMEOUTMS   │ timeoutms           │ liseconds to  block │
427          │                    │                     │ for  server  selec‐ │
428          │                    │                     │ tion before  throw‐ │
429          │                    │                     │ ing  an  exception. │
430          │                    │                     │ The   default    is │
431          │                    │                     │ 30,0000ms  (30 sec‐ │
432          │                    │                     │ onds).              │
433          ├────────────────────┼─────────────────────┼─────────────────────┤
434          │MONGOC_URI_SERVERS‐ │ serverselectiontry‐ │ If   "true",    the │
435          │ELECTIONTRYONCE     │ once                │ driver   scans  the │
436          │                    │                     │ topology    exactly │
437          │                    │                     │ once  after  server │
438          │                    │                     │ selection    fails, │
439          │                    │                     │ then either selects │
440          │                    │                     │ a server or returns │
441          │                    │                     │ an  error. If it is │
442          │                    │                     │ false,   then   the │
443          │                    │                     │ driver   repeatedly │
444          │                    │                     │ searches   for    a │
445          │                    │                     │ suitable server for │
446          │                    │                     │ up to  serverSelec‐ 
447          │                    │                     │ tionTimeoutMS  mil‐ │
448          │                    │                     │ liseconds  (pausing │
449          │                    │                     │ a    half    second │
450          │                    │                     │ between  attempts). │
451          │                    │                     │ The   default   for │
452          │                    │                     │ serverSelectionTry‐ 
453          │                    │                     │ Once is "false" for │
454          │                    │                     │ pooled     clients, │
455          │                    │                     │ otherwise   "true". │
456          │                    │                     │ Pooled      clients │
457          │                    │                     │ ignore serverSelec‐ │
458          │                    │                     │ tionTryOnce;   they │
459          │                    │                     │ signal  the  thread │
460          │                    │                     │ to    rescan    the │
461          │                    │                     │ topology      every │
462          │                    │                     │ half-second   until │
463          │                    │                     │ serverSelection‐    │
464          │                    │                     │ TimeoutMS expires.  │
465          ├────────────────────┼─────────────────────┼─────────────────────┤
466          │MONGOC_URI_SOCK‐    │ socketcheckinter‐   │ Only   applies   to │
467          │ETCHECKINTERVALMS   │ valms               │ single     threaded │
468          │                    │                     │ clients.    If    a │
469          │                    │                     │ socket has not been │
470          │                    │                     │ used  within   this │
471          │                    │                     │ time,  its  connec‐ │
472          │                    │                     │ tion   is   checked │
473          │                    │                     │ with     a    quick │
474          │                    │                     │ "isMaster"     call │
475          │                    │                     │ before  it  is used │
476          │                    │                     │ again. Defaults  to │
477          │                    │                     │ 5,000ms   (5   sec‐ │
478          │                    │                     │ onds).              │
479          └────────────────────┴─────────────────────┴─────────────────────┘
480
481
482
483          │MONGOC_URI_DIRECT‐  │ directconnection    │ If    "true",   the │
484          │CONNECTION          │                     │ driver connects  to │
485          │                    │                     │ a   single   server │
486          │                    │                     │ directly  and  will │
487          │                    │                     │ not  monitor  addi‐ │
488          │                    │                     │ tional servers.  If │
489          │                    │                     │ "false", the driver │
490          │                    │                     │ connects  based  on │
491          │                    │                     │ the   presence  and │
492          │                    │                     │ value of the repli‐ 
493          │                    │                     │ caSet option.       │
494          └────────────────────┴─────────────────────┴─────────────────────┘
495
496       Setting any of the *TimeoutMS options above to 0 will be interpreted as
497       "use the default value".
498

CONNECTION POOL OPTIONS

500       These options govern the behavior of a mongoc_client_pool_t.  They  are
501       ignored by a non-pooled mongoc_client_t.
502
503          ┌────────────────────┬────────────────────┬─────────────────────┐
504          │Constant            │ Key                │ Description         │
505          ├────────────────────┼────────────────────┼─────────────────────┤
506          │MONGOC_URI_MAXPOOL‐ │ maxpoolsize        │ The maximum  number │
507          │SIZE                │                    │ of  clients created │
508          │                    │                    │ by      a      mon‐ 
509          │                    │                    │ goc_client_pool_t   
510          │                    │                    │ total (both in  the │
511          │                    │                    │ pool   and  checked │
512          │                    │                    │ out).  The  default │
513          │                    │                    │ value  is 100. Once │
514          │                    │                    │ it is reached, mon‐ 
515          │                    │                    │ goc_client_pool_pop 
516          │                    │                    │ blocks        until │
517          │                    │                    │ another      thread │
518          │                    │                    │ pushes a client.    │
519          ├────────────────────┼────────────────────┼─────────────────────┤
520          │MONGOC_URI_MINPOOL‐ │ minpoolsize        │ Deprecated.    This │
521          │SIZE                │                    │ option's   behavior │
522          │                    │                    │ does  not match its │
523          │                    │                    │ name,    and    its │
524          │                    │                    │ actual     behavior │
525          │                    │                    │ will  likely   hurt │
526          │                    │                    │ performance.        │
527          ├────────────────────┼────────────────────┼─────────────────────┤
528          │MONGOC_URI_MAXIDLE‐ │ maxidletimems      │ Not implemented.    │
529          │TIMEMS              │                    │                     │
530          ├────────────────────┼────────────────────┼─────────────────────┤
531          │MONGOC_URI_WAIT‐    │ waitqueuemultiple  │ Not implemented.    │
532          │QUEUEMULTIPLE       │                    │                     │
533          ├────────────────────┼────────────────────┼─────────────────────┤
534          │MONGOC_URI_WAIT‐    │ waitqueuetimeoutms │ The maximum time to │
535          │QUEUETIMEOUTMS      │                    │ wait  for  a client │
536          │                    │                    │ to become available │
537          │                    │                    │ from the pool.      │
538          └────────────────────┴────────────────────┴─────────────────────┘
539

WRITE CONCERN OPTIONS

541               ┌───────────────────┬────────────┬─────────────────────┐
542               │Constant           │ Key        │ Description         │
543               └───────────────────┴────────────┴─────────────────────┘
544
545
546
547
548
549
550
551
552
553                MONGOC_URI_W         w            Determines      the
554                                                  write       concern
555                                                  (guarantee).  Valid
556                                                  values:
557
558                                                         · 0  =   The
559                                                           driver
560                                                           will   not
561                                                           acknowl‐
562                                                           edge write
563                                                           operations
564                                                           but   will
565                                                           pass    or
566                                                           handle any
567                                                           network
568                                                           and socket
569                                                           errors
570                                                           that    it
571                                                           receives
572                                                           to     the
573                                                           client. If
574                                                           you   dis‐
575                                                           able write
576                                                           concern
577                                                           but enable
578                                                           the   get‐
579                                                           LastError
580                                                           command’s
581                                                           w  option,
582                                                           w    over‐
583                                                           rides  the
584                                                           w option.
585
586                                                         · 1  =  Pro‐
587                                                           vides
588                                                           basic
589                                                           acknowl‐
590                                                           edgement
591                                                           of   write
592                                                           opera‐
593                                                           tions.  By
594                                                           specifying
595                                                           1,     you
596                                                           require
597                                                           that     a
598                                                           standalone
599                                                           mongod
600                                                           instance,
601                                                           or     the
602                                                           primary
603                                                           for
604                                                           replica
605                                                           sets,
606                                                           acknowl‐
607                                                           edge   all
608                                                           write
609                                                           opera‐
610                                                           tions. For
611                                                           drivers
612                                                           released
613                                                           after  the
614                                                           default
615                                                           write con‐
616                                                           cern
617                                                           change,
618                                                           this    is
619                                                           the
620                                                           default
621                                                           write con‐
622                                                           cern  set‐
623                                                           ting.
624
625                                                         · majority =
626                                                           For
627                                                           replica
628                                                           sets,   if
629                                                           you  spec‐
630                                                           ify    the
631                                                           special
632                                                           majority
633                                                           value to w
634                                                           option,
635                                                           write
636                                                           operations
637                                                           will  only
638                                                           return
639                                                           success‐
640                                                           fully
641                                                           after    a
642                                                           majority
643                                                           of     the
644                                                           configured
645                                                           replica
646                                                           set   mem‐
647                                                           bers  have
648                                                           acknowl‐
649                                                           edged  the
650                                                           write
651                                                           operation.
652
653                                                         · n   =  For
654                                                           replica
655                                                           sets,   if
656                                                           you  spec‐
657                                                           ify a num‐
658                                                           ber      n
659                                                           greater
660                                                           than    1,
661                                                           operations
662                                                           with  this
663                                                           write con‐
664                                                           cern
665                                                           return
666                                                           only after
667                                                           n  members
668                                                           of the set
669                                                           have
670                                                           acknowl‐
671                                                           edged  the
672                                                           write.  If
673                                                           you  set n
674                                                           to a  num‐
675                                                           ber   that
676                                                           is greater
677                                                           than   the
678                                                           number  of
679                                                           available
680                                                           set   mem‐
681                                                           bers    or
682                                                           members
683                                                           that  hold
684                                                           data, Mon‐
685                                                           goDB  will
686                                                           wait,
687                                                           poten‐
688                                                           tially
689                                                           indefi‐
690                                                           nitely,
691                                                           for  these
692                                                           members to
693                                                           become
694                                                           available.
695
696                                                         · tags = For
697                                                           replica
698                                                           sets,  you
699                                                           can  spec‐
700                                                           ify a  tag
701                                                           set     to
702                                                           require
703                                                           that   all
704                                                           members of
705                                                           the    set
706                                                           that  have
707                                                           these tags
708                                                           configured
709                                                           return
710                                                           confirma‐
711                                                           tion    of
712                                                           the  write
713                                                           operation.
714               ├───────────────────┼────────────┼─────────────────────┤
715               │MONGOC_URI_WTIME‐  │ wtimeoutms │ The  time  in  mil‐ │
716               │OUTMS              │            │ liseconds  to  wait │
717               │                   │            │ for replication  to │
718               │                   │            │ succeed,  as speci‐ │
719               │                   │            │ fied   in   the   w │
720               │                   │            │ option, before tim‐ │
721               │                   │            │ ing    out.    When │
722               │                   │            │ wtimeoutMS   is  0, │
723               │                   │            │ write    operations │
724               │                   │            │ will   never   time │
725               │                   │            │ out.                │
726               ├───────────────────┼────────────┼─────────────────────┤
727               │MONGOC_URI_JOURNAL │ journal    │ Controls    whether │
728               │                   │            │ write    operations │
729               │                   │            │ will wait until the │
730               │                   │            │ mongod acknowledges │
731               │                   │            │ the  write   opera‐ │
732               │                   │            │ tions  and  commits │
733               │                   │            │ the data to the  on │
734               │                   │            │ disk journal.       │
735               │                   │            │                     │
736               │                   │            │        · true     = │
737               │                   │            │          Enables    │
738               │                   │            │          journal    │
739               │                   │            │          commit     │
740               │                   │            │          acknowl‐   │
741               │                   │            │          edgement   │
742               │                   │            │          write con‐ │
743               │                   │            │          cern.      │
744               │                   │            │          Equivalent │
745               │                   │            │          to  speci‐ │
746               │                   │            │          fying  the │
747               │                   │            │          getLastEr‐ │
748               │                   │            │          ror   com‐ │
749               │                   │            │          mand  with │
750               │                   │            │          the      j │
751               │                   │            │          option     │
752               │                   │            │          enabled.   │
753               │                   │            │                     │
754               │                   │            │        · false    = │
755               │                   │            │          Does   not │
756               │                   │            │          require    │
757               │                   │            │          that  mon‐ │
758               │                   │            │          god commit │
759               │                   │            │          write      │
760               │                   │            │          operations │
761               │                   │            │          to     the │
762               │                   │            │          journal    │
763               │                   │            │          before     │
764               │                   │            │          acknowl‐   │
765               │                   │            │          edging the │
766               │                   │            │          write      │
767               │                   │            │          operation. │
768               │                   │            │          This    is │
769               │                   │            │          the        │
770               │                   │            │          default    │
771               │                   │            │          option for │
772               │                   │            │          the  jour‐ │
773               │                   │            │          nal param‐ │
774               │                   │            │          eter.      │
775               └───────────────────┴────────────┴─────────────────────┘
776

READ CONCERN OPTIONS

778           ┌────────────────────┬──────────────────┬─────────────────────┐
779           │Constant            │ Key              │ Description         │
780           └────────────────────┴──────────────────┴─────────────────────┘
781
782
783
784           │MONGOC_URI_READCON‐ │ readconcernlevel │ The level of isola‐ │
785           │CERNLEVEL           │                  │ tion for read oper‐ │
786           │                    │                  │ ations.   If    the │
787           │                    │                  │ level    is    left │
788           │                    │                  │ unspecified,    the │
789           │                    │                  │ server default will │
790           │                    │                  │ be    used.     See │
791           │                    │                  │ readConcern  in the
792           │                    │                  │ MongoDB Manual  for │
793           │                    │                  │ details.            │
794           └────────────────────┴──────────────────┴─────────────────────┘
795

READ PREFERENCE OPTIONS

797       When  connected  to  a  replica set, the driver chooses which member to
798       query using the read preference:
799
800       1. Choose members whose type matches "readPreference".
801
802       2. From these, if there are any tags sets  configured,  choose  members
803          matching the first tag set. If there are none, fall back to the next
804          tag set and so on, until some members are chosen or the tag sets are
805          exhausted.
806
807       3. From  the  chosen  servers,  distribute  queries  randomly among the
808          server with the fastest round-trip times. These include  the  server
809          with  the fastest time and any whose round-trip time is no more than
810          "localThresholdMS" slower.
811
812       ┌─────────────────────┬─────────────────────┬──────────────────────────┐
813       │Constant             │ Key                 │ Description              │
814       ├─────────────────────┼─────────────────────┼──────────────────────────┤
815       │MONGOC_URI_READ‐     │ readpreference      │ Specifies       the      │
816       │PREFERENCE           │                     │ replica  set   read      │
817       │                     │                     │ preference for this      │
818       │                     │                     │ connection.    This      │
819       │                     │                     │ setting   overrides      │
820       │                     │                     │ any slaveOk  value.      │
821       │                     │                     │ The read preference      │
822       │                     │                     │ values are the fol‐      │
823       │                     │                     │ lowing:                  │
824       │                     │                     │                          │
825       │                     │                     │        · primary         │
826       │                     │                     │          (default)       │
827       │                     │                     │                          │
828       │                     │                     │        · prima‐          │
829       │                     │                     │          ryPre‐          │
830       │                     │                     │          ferred          │
831       │                     │                     │                          │
832       │                     │                     │        · secondary       │
833       │                     │                     │                          │
834       │                     │                     │        · sec‐            │
835       │                     │                     │          ondaryPre‐      │
836       │                     │                     │          ferred          │
837       │                     │                     │                          │
838       │                     │                     │        · nearest         │
839       ├─────────────────────┼─────────────────────┼──────────────────────────┤
840       │MONGOC_URI_READ‐     │ readpreferencetags  │ A representation of      │
841       │PREFERENCETAGS       │                     │ a tag set. See also      │
842       │                     │                     │ mon‐                     │
843       │                     │                     │ goc-read-prefs-tag-sets. │
844       └─────────────────────┴─────────────────────┴──────────────────────────┘
845
846
847
848
849
850
851
852
853
854       │MON‐                 │ localthresholdms    │ How  far  to  distribute │
855       │GOC_URI_LOCALTHRESH‐ │                     │ queries,   beyond    the │
856       │OLDMS                │                     │ server  with the fastest │
857       │                     │                     │ round-trip   time.    By │
858       │                     │                     │ default,   only  servers │
859       │                     │                     │ within   15ms   of   the │
860       │                     │                     │ fastest  round-trip time │
861       │                     │                     │ receive queries.         │
862       ├─────────────────────┼─────────────────────┼──────────────────────────┤
863       │MONGOC_URI_MAXSTALE‐ │ maxstalenessseconds │ The  maximum replication │
864       │NESSSECONDS          │                     │ lag, in wall clock time, │
865       │                     │                     │ that   a  secondary  can │
866       │                     │                     │ suffer and still be eli‐ │
867       │                     │                     │ gible.    The   smallest │
868       │                     │                     │ allowed    value     for │
869       │                     │                     │ maxStalenessSeconds   is │
870       │                     │                     │ 90 seconds.              │
871       └─────────────────────┴─────────────────────┴──────────────────────────┘
872
873       NOTE:
874          When connecting to more than one  mongos,  libmongoc's  localThresh‐
875          oldMS applies only to the selection of mongos servers. The threshold
876          for selecting among replica set members in shards is  controlled  by
877          the mongos's localThreshold command line option.
878

LEGACY OPTIONS

880       For  historical  reasons,  the  following  options  are available. They
881       should however not be used.
882
883                ┌───────────────────┬─────────┬─────────────────────┐
884                │Constant           │ Key     │ Description         │
885                ├───────────────────┼─────────┼─────────────────────┤
886                │MONGOC_URI_SAFE    │ safe    │ {true|false}   Same │
887                │                   │         │ as w={1|0}          │
888                ├───────────────────┼─────────┼─────────────────────┤
889                │MONGOC_URI_SLAVEOK │ slaveok │ When  set,  same as │
890                │                   │         │ readPreference=sec‐ │
891                │                   │         │ ondaryPreferred     │
892                └───────────────────┴─────────┴─────────────────────┘
893

AUTHOR

895       MongoDB, Inc
896
898       2017-present, MongoDB, Inc
899
900
901
902
9031.17.4                           Feb 04, 2021                  MONGOC_URI_T(3)
Impressum