Struct ClientOptions

Source
#[non_exhaustive]
pub struct ClientOptions {
Show 31 fields pub hosts: Vec<ServerAddress>, pub app_name: Option<String>, pub compressors: Option<Vec<Compressor>>, pub cmap_event_handler: Option<EventHandler<CmapEvent>>, pub command_event_handler: Option<EventHandler<CommandEvent>>, 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 server_monitoring_mode: Option<ServerMonitoringMode>, pub sdam_event_handler: Option<EventHandler<SdamEvent>>, pub selection_criteria: Option<SelectionCriteria>, pub server_api: Option<ServerApi>, pub server_selection_timeout: Option<Duration>, pub default_database: Option<String>, pub srv_service_name: 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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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>>
Available on crate features zstd-compression or zlib-compression or snappy-compression only.

The allowed compressors to use to compress messages sent to and decompress messages received from the server. This list should be specified in priority order, as the compressor used for messages will be the first compressor in this list that is also supported by the server selected for operations.

§cmap_event_handler: Option<EventHandler<CmapEvent>>

The handler that should process all Connection Monitoring and Pooling events.

§command_event_handler: Option<EventHandler<CommandEvent>>

The handler that should process all command-related events.

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.

§server_monitoring_mode: Option<ServerMonitoringMode>

Configures which server monitoring protocol to use.

The default is Auto.

§sdam_event_handler: Option<EventHandler<SdamEvent>>

The handler that should process all Server Discovery and Monitoring events.

§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.

§srv_service_name: Option<String>

Overrides the default “mongodb” service name for SRV lookup in both discovery and polling

§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>
Available on crate feature 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

Source

pub fn parse<C, E>(conn_str: C) -> ParseConnectionString
where C: TryInto<ConnectionString, Error = E>, E: Into<Error>,

Parses a MongoDB connection string (as either a &str or a ConnectionString) into a ClientOptions struct. If the string is malformed or one of the options has an invalid value, an error will be returned.

In the case that “mongodb+srv” is used, SRV and TXT record lookups will be done as part of this method.

The format of a MongoDB connection string is described here.

Note that default_database will be set from /defaultauthdb in connection string.

The following options are supported in the options query string:

  • appName: maps to the app_name field
  • authMechanism: maps to the mechanism field of the credential field
  • authSource: maps to the source field of the credential field
  • authMechanismProperties: maps to the mechanism_properties field of the credential field
  • compressors: maps to the compressors field
  • connectTimeoutMS: maps to the connect_timeout field
  • direct: maps to the direct field
  • heartbeatFrequencyMS: maps to the heartbeat_frequency field
  • journal: maps to the journal field of the write_concern field
  • localThresholdMS: maps to the local_threshold field
  • maxIdleTimeMS: maps to the max_idle_time field
  • maxStalenessSeconds: maps to the max_staleness field of the selection_criteria field
  • maxPoolSize: maps to the max_pool_size field
  • minPoolSize: maps to the min_pool_size field
  • readConcernLevel: maps to the read_concern field
  • readPreferenceField: maps to the ReadPreference enum variant of the selection_criteria field
  • readPreferenceTags: maps to the tags field of the selection_criteria field. Note that this option can appear more than once; each instance will be mapped to a separate tag set
  • replicaSet: maps to the repl_set_name field
  • retryWrites: not yet implemented
  • retryReads: maps to the retry_reads field
  • serverSelectionTimeoutMS: maps to the server_selection_timeout field
  • socketTimeoutMS: unsupported, does not map to any field
  • ssl: an alias of the tls option
  • tls: maps to the TLS variant of the tls field`.
  • tlsInsecure: relaxes the TLS constraints on connections being made; currently is just an alias of tlsAllowInvalidCertificates, but more behavior may be added to this option in the future
  • tlsAllowInvalidCertificates: maps to the allow_invalidCertificates field of the tls field
  • tlsCAFile: maps to the ca_file_path field of the tls field
  • tlsCertificateKeyFile: maps to the cert_key_file_path field of the tls field
  • w: maps to the w field of the write_concern field
  • waitQueueTimeoutMS: unsupported, does not map to any field
  • wTimeoutMS: maps to the w_timeout field of the write_concern field
  • zlibCompressionLevel: maps to the level field of the Compressor::Zlib variant (which requires the zlib-compression feature flag) of the Compressor enum

await will return Result<ClientOptions>.

These methods can be chained before .await to set options:

Source§

impl ClientOptions

Source

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), .server_monitoring_mode(...)(optional), .sdam_event_handler(...)(optional), .selection_criteria(...)(optional), .server_api(...)(optional), .server_selection_timeout(...)(optional), .default_database(...)(optional), .srv_service_name(...)(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.

Trait Implementations§

Source§

impl Clone for ClientOptions

Source§

fn clone(&self) -> ClientOptions

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientOptions

Source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ClientOptions

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ClientOptions

Source§

fn eq(&self, __other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .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
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .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
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,