Struct mongodb::options::ClientOptions
source · #[non_exhaustive]pub struct ClientOptions {Show 29 fields
pub hosts: Vec<ServerAddress>,
pub app_name: Option<String>,
pub compressors: Option<Vec<Compressor>>,
pub cmap_event_handler: Option<Arc<dyn CmapEventHandler>>,
pub command_event_handler: Option<Arc<dyn CommandEventHandler>>,
pub connect_timeout: Option<Duration>,
pub credential: Option<Credential>,
pub direct_connection: Option<bool>,
pub driver_info: Option<DriverInfo>,
pub heartbeat_freq: Option<Duration>,
pub load_balanced: Option<bool>,
pub local_threshold: Option<Duration>,
pub max_idle_time: Option<Duration>,
pub max_pool_size: Option<u32>,
pub min_pool_size: Option<u32>,
pub max_connecting: Option<u32>,
pub read_concern: Option<ReadConcern>,
pub repl_set_name: Option<String>,
pub retry_reads: Option<bool>,
pub retry_writes: Option<bool>,
pub sdam_event_handler: Option<Arc<dyn SdamEventHandler>>,
pub selection_criteria: Option<SelectionCriteria>,
pub server_api: Option<ServerApi>,
pub server_selection_timeout: Option<Duration>,
pub default_database: Option<String>,
pub tls: Option<Tls>,
pub tracing_max_document_length_bytes: Option<usize>,
pub write_concern: Option<WriteConcern>,
pub srv_max_hosts: Option<u32>,
/* private fields */
}
Expand description
Contains the options that can be used to create a new Client
.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.hosts: Vec<ServerAddress>
The initial list of seeds that the Client should connect to.
Note that by default, the driver will autodiscover other nodes in the cluster. To connect
directly to a single server (rather than autodiscovering the rest of the cluster), set the
direct_connection
field to true
.
app_name: Option<String>
The application name that the Client will send to the server as part of the handshake. This can be used in combination with the server logs to determine which Client is connected to a server.
compressors: Option<Vec<Compressor>>
The compressors that the Client is willing to use in the order they are specified in the configuration. The Client sends this list of compressors to the server. The server responds with the intersection of its supported list of compressors. The order of compressors indicates preference of compressors.
cmap_event_handler: Option<Arc<dyn CmapEventHandler>>
The handler that should process all Connection Monitoring and Pooling events. See the CmapEventHandler type documentation for more details.
command_event_handler: Option<Arc<dyn CommandEventHandler>>
The handler that should process all command-related events. See the CommandEventHandler type documentation for more details.
Note that monitoring command events may incur a performance penalty.
connect_timeout: Option<Duration>
The connect timeout passed to each underlying TcpStream when attemtping to connect to the server.
The default value is 10 seconds.
credential: Option<Credential>
The credential to use for authenticating connections made by this client.
direct_connection: Option<bool>
Specifies whether the Client should directly connect to a single host rather than autodiscover all servers in the cluster.
The default value is false.
driver_info: Option<DriverInfo>
Extra information to append to the driver version in the metadata of the handshake with the server. This should be used by libraries wrapping the driver, e.g. ODMs.
heartbeat_freq: Option<Duration>
The amount of time each monitoring thread should wait between performing server checks.
The default value is 10 seconds.
load_balanced: Option<bool>
Whether or not the client is connecting to a MongoDB cluster through a load balancer.
local_threshold: Option<Duration>
When running a read operation with a ReadPreference that allows selecting secondaries,
local_threshold
is used to determine how much longer the average round trip time between
the driver and server is allowed compared to the least round trip time of all the suitable
servers. For example, if the average round trip times of the suitable servers are 5 ms, 10
ms, and 15 ms, and the local threshold is 8 ms, then the first two servers are within the
latency window and could be chosen for the operation, but the last one is not.
A value of zero indicates that there is no latency window, so only the server with the lowest average round trip time is eligible.
The default value is 15 ms.
max_idle_time: Option<Duration>
The amount of time that a connection can remain idle in a connection pool before being closed. A value of zero indicates that connections should not be closed due to being idle.
By default, connections will not be closed due to being idle.
max_pool_size: Option<u32>
The maximum amount of connections that the Client should allow to be created in a
connection pool for a given server. If an operation is attempted on a server while
max_pool_size
connections are checked out, the operation will block until an in-progress
operation finishes and its connection is checked back into the pool.
The default value is 10.
min_pool_size: Option<u32>
The minimum number of connections that should be available in a server’s connection pool at
a given time. If fewer than min_pool_size
connections are in the pool, connections will
be added to the pool in the background until min_pool_size
is reached.
The default value is 0.
max_connecting: Option<u32>
The maximum number of new connections that can be created concurrently.
If specified, this value must be greater than 0. The default is 2.
read_concern: Option<ReadConcern>
Specifies the default read concern for operations performed on the Client. See the ReadConcern type documentation for more details.
repl_set_name: Option<String>
The name of the replica set that the Client should connect to.
retry_reads: Option<bool>
Whether or not the client should retry a read operation if the operation fails.
The default value is true.
retry_writes: Option<bool>
Whether or not the client should retry a write operation if the operation fails.
The default value is true.
sdam_event_handler: Option<Arc<dyn SdamEventHandler>>
The handler that should process all Server Discovery and Monitoring events. See the
SdamEventHandler
type documentation for more details.
selection_criteria: Option<SelectionCriteria>
The default selection criteria for operations performed on the Client. See the SelectionCriteria type documentation for more details.
server_api: Option<ServerApi>
The declared API version for this client. The declared API version is applied to all commands run through the client, including those sent through any handle derived from the client.
Specifying stable API options in the command document passed to run_command
AND
declaring an API version on the client is not supported and is considered undefined
behaviour. To run any command with a different API version or without declaring one, create
a separate client that declares the appropriate API version.
For more information, see the Stable API manual page.
server_selection_timeout: Option<Duration>
The amount of time the Client should attempt to select a server for an operation before timing outs
The default value is 30 seconds.
default_database: Option<String>
Default database for this client.
By default, no default database is specified.
tls: Option<Tls>
The TLS configuration for the Client to use in its connections with the server.
By default, TLS is disabled.
tracing_max_document_length_bytes: Option<usize>
tracing-unstable
only.The maximum number of bytes that the driver should include in a tracing event or log message’s extended JSON string representation of a BSON document, e.g. a command or reply from the server. If truncation of a document at the exact specified length would occur in the middle of a Unicode codepoint, the document will be truncated at the closest larger length which falls on a boundary between codepoints. Note that in cases where truncation occurs the output will not be valid JSON.
The default value is 1000.
write_concern: Option<WriteConcern>
Specifies the default write concern for operations performed on the Client. See the WriteConcern type documentation for more details.
srv_max_hosts: Option<u32>
Limit on the number of mongos connections that may be created for sharded topologies.
Implementations§
source§impl ClientOptions
impl ClientOptions
sourcepub fn builder(
) -> ClientOptionsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
pub fn builder( ) -> ClientOptionsBuilder<((), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ())>
Create a builder for building ClientOptions
.
On the builder, call .hosts(...)
(optional), .app_name(...)
(optional), .compressors(...)
(optional), .cmap_event_handler(...)
(optional), .command_event_handler(...)
(optional), .connect_timeout(...)
(optional), .credential(...)
(optional), .direct_connection(...)
(optional), .driver_info(...)
(optional), .heartbeat_freq(...)
(optional), .local_threshold(...)
(optional), .max_idle_time(...)
(optional), .max_pool_size(...)
(optional), .min_pool_size(...)
(optional), .max_connecting(...)
(optional), .read_concern(...)
(optional), .repl_set_name(...)
(optional), .retry_reads(...)
(optional), .retry_writes(...)
(optional), .sdam_event_handler(...)
(optional), .selection_criteria(...)
(optional), .server_api(...)
(optional), .server_selection_timeout(...)
(optional), .default_database(...)
(optional), .tls(...)
(optional), .tracing_max_document_length_bytes(...)
(optional), .write_concern(...)
(optional), .srv_max_hosts(...)
(optional) to set the values of the fields.
Finally, call .build()
to create the instance of ClientOptions
.
source§impl ClientOptions
impl ClientOptions
sourcepub fn parse(s: impl AsRef<str>) -> Result<Self>
Available on crate features sync
or tokio-sync
only.
pub fn parse(s: impl AsRef<str>) -> Result<Self>
sync
or tokio-sync
only.This method will be present if the sync
feature is enabled. It’s otherwise identical to
the async version
sourcepub async fn parse_async(s: impl AsRef<str>) -> Result<Self>
pub async fn parse_async(s: impl AsRef<str>) -> Result<Self>
This method is the same as parse
, but is provided to make the async version available when
the sync
feature is enabled.
sourcepub fn parse_with_resolver_config(
uri: &str,
resolver_config: ResolverConfig
) -> Result<Self>
Available on crate features sync
or tokio-sync
only.
pub fn parse_with_resolver_config( uri: &str, resolver_config: ResolverConfig ) -> Result<Self>
sync
or tokio-sync
only.This method will be present if the sync
feature is enabled. It’s otherwise identical to
the async version
sourcepub async fn parse_connection_string_with_resolver_config(
conn_str: ConnectionString,
resolver_config: ResolverConfig
) -> Result<Self>
pub async fn parse_connection_string_with_resolver_config( conn_str: ConnectionString, resolver_config: ResolverConfig ) -> Result<Self>
Creates a ClientOptions
from the given ConnectionString
.
In the case that “mongodb+srv” is used, SRV and TXT record lookups will be done using the
provided ResolverConfig
as part of this method.
sourcepub async fn parse_connection_string(conn_str: ConnectionString) -> Result<Self>
pub async fn parse_connection_string(conn_str: ConnectionString) -> Result<Self>
Creates a ClientOptions
from the given ConnectionString
.
sourcepub fn parse_connection_string_sync(conn_str: ConnectionString) -> Result<Self>
Available on crate features sync
or tokio-sync
only.
pub fn parse_connection_string_sync(conn_str: ConnectionString) -> Result<Self>
sync
or tokio-sync
only.Creates a ClientOptions
from the given ConnectionString
.
sourcepub fn parse_connection_string_with_resolver_config_sync(
conn_str: ConnectionString,
resolver_config: ResolverConfig
) -> Result<Self>
Available on crate features sync
or tokio-sync
only.
pub fn parse_connection_string_with_resolver_config_sync( conn_str: ConnectionString, resolver_config: ResolverConfig ) -> Result<Self>
sync
or tokio-sync
only.Creates a ClientOptions
from the given ConnectionString
.
In the case that “mongodb+srv” is used, SRV and TXT record lookups will be done using the
provided ResolverConfig
as part of this method.
Trait Implementations§
source§impl Clone for ClientOptions
impl Clone for ClientOptions
source§fn clone(&self) -> ClientOptions
fn clone(&self) -> ClientOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ClientOptions
impl Debug for ClientOptions
source§impl Default for ClientOptions
impl Default for ClientOptions
source§impl<'de> Deserialize<'de> for ClientOptions
impl<'de> Deserialize<'de> for ClientOptions
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ClientOptions
impl !RefUnwindSafe for ClientOptions
impl Send for ClientOptions
impl Sync for ClientOptions
impl Unpin for ClientOptions
impl !UnwindSafe for ClientOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.