Table of Contents

Class MongoUrl

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

Represents an immutable URL style connection string. See also MongoUrlBuilder.

[Serializable]
[TypeConverter(typeof(MongoUrlTypeConverter))]
public class MongoUrl : IEquatable<MongoUrl>
Inheritance
MongoUrl
Implements
Inherited Members

Constructors

MongoUrl(string)

Creates a new instance of MongoUrl.

public MongoUrl(string url)

Parameters

url string

The URL containing the settings.

Properties

AllowInsecureTls

Gets whether to relax TLS constraints as much as possible.

public bool AllowInsecureTls { get; }

Property Value

bool

ApplicationName

Gets the application name.

public string ApplicationName { get; }

Property Value

string

AuthenticationMechanism

Gets the authentication mechanism.

public string AuthenticationMechanism { get; }

Property Value

string

AuthenticationMechanismProperties

Gets the authentication mechanism properties.

public IEnumerable<KeyValuePair<string, string>> AuthenticationMechanismProperties { get; }

Property Value

IEnumerable<KeyValuePair<string, string>>

AuthenticationSource

Gets the authentication source.

public string AuthenticationSource { get; }

Property Value

string

Compressors

Gets the compressors.

public IReadOnlyList<CompressorConfiguration> Compressors { get; }

Property Value

IReadOnlyList<CompressorConfiguration>

ComputedWaitQueueSize

Gets the actual wait queue size (either WaitQueueSize or WaitQueueMultiple x MaxConnectionPoolSize).

[Obsolete("This property will be removed in a later release.")]
public int ComputedWaitQueueSize { get; }

Property Value

int

ConnectTimeout

Gets the connect timeout.

public TimeSpan ConnectTimeout { get; }

Property Value

TimeSpan

ConnectionMode

Gets the connection mode.

[Obsolete("Use DirectConnection instead.")]
public ConnectionMode ConnectionMode { get; }

Property Value

ConnectionMode

ConnectionModeSwitch

Gets the connection mode switch.

[Obsolete("This property will be removed in a later release.")]
public ConnectionModeSwitch ConnectionModeSwitch { get; }

Property Value

ConnectionModeSwitch

DatabaseName

Gets the optional database name.

public string DatabaseName { get; }

Property Value

string

DirectConnection

Gets the direct connection.

public bool? DirectConnection { get; }

Property Value

bool?

FSync

Gets the FSync component of the write concern.

public bool? FSync { get; }

Property Value

bool?

GuidRepresentation

Gets the representation to use for Guids.

[Obsolete("Configure serializers instead.")]
public GuidRepresentation GuidRepresentation { get; }

Property Value

GuidRepresentation

HasAuthenticationSettings

Gets a value indicating whether this instance has authentication settings.

public bool HasAuthenticationSettings { get; }

Property Value

bool

HeartbeatInterval

Gets the heartbeat interval.

public TimeSpan HeartbeatInterval { get; }

Property Value

TimeSpan

HeartbeatTimeout

Gets the heartbeat timeout.

public TimeSpan HeartbeatTimeout { get; }

Property Value

TimeSpan

IPv6

Gets a value indicating whether to use IPv6.

public bool IPv6 { get; }

Property Value

bool

IsResolved

Gets a value indicating whether a connection string with scheme MongoDBPlusSrv has been resolved.

public bool IsResolved { get; }

Property Value

bool

Journal

Gets the Journal component of the write concern.

public bool? Journal { get; }

Property Value

bool?

LoadBalanced

Gets or sets whether load balanced mode is used.

public bool LoadBalanced { get; }

Property Value

bool

LocalThreshold

Gets the local threshold.

public TimeSpan LocalThreshold { get; }

Property Value

TimeSpan

MaxConnecting

Gets the maximum concurrently connecting connections.

public int MaxConnecting { get; }

Property Value

int

MaxConnectionIdleTime

Gets the max connection idle time.

public TimeSpan MaxConnectionIdleTime { get; }

Property Value

TimeSpan

MaxConnectionLifeTime

Gets the max connection life time.

public TimeSpan MaxConnectionLifeTime { get; }

Property Value

TimeSpan

MaxConnectionPoolSize

Gets the max connection pool size.

public int MaxConnectionPoolSize { get; }

Property Value

int

MinConnectionPoolSize

Gets the min connection pool size.

public int MinConnectionPoolSize { get; }

Property Value

int

Password

Gets the password.

public string Password { get; }

Property Value

string

ReadConcernLevel

Gets the read concern level.

public ReadConcernLevel? ReadConcernLevel { get; }

Property Value

ReadConcernLevel?

ReadPreference

Gets the read preference.

public ReadPreference ReadPreference { get; }

Property Value

ReadPreference

ReplicaSetName

Gets the name of the replica set.

public string ReplicaSetName { get; }

Property Value

string

RetryReads

Gets whether reads will be retried.

public bool? RetryReads { get; }

Property Value

bool?

RetryWrites

Gets whether writes will be retried.

public bool? RetryWrites { get; }

Property Value

bool?

Scheme

Gets the connection string scheme.

public ConnectionStringScheme Scheme { get; }

Property Value

ConnectionStringScheme

Server

Gets the address of the server (see also Servers if using more than one address).

public MongoServerAddress Server { get; }

Property Value

MongoServerAddress

ServerSelectionTimeout

Gets the server selection timeout.

public TimeSpan ServerSelectionTimeout { get; }

Property Value

TimeSpan

Servers

Gets the list of server addresses (see also Server if using only one address).

public IEnumerable<MongoServerAddress> Servers { get; }

Property Value

IEnumerable<MongoServerAddress>

SocketTimeout

Gets the socket timeout.

public TimeSpan SocketTimeout { get; }

Property Value

TimeSpan

SrvMaxHosts

Limits the number of SRV records used to populate the seedlist during initial discovery, as well as the number of additional hosts that may be added during SRV polling.

public int? SrvMaxHosts { get; }

Property Value

int?

TlsDisableCertificateRevocationCheck

Gets whether or not to disable checking certificate revocation status during the TLS handshake.

public bool TlsDisableCertificateRevocationCheck { get; }

Property Value

bool

Url

Gets the URL (in canonical form).

public string Url { get; }

Property Value

string

UseSsl

Gets a value indicating whether to use SSL.

[Obsolete("Use UseTls instead.")]
public bool UseSsl { get; }

Property Value

bool

UseTls

Gets a value indicating whether to use TLS.

public bool UseTls { get; }

Property Value

bool

Username

Gets the username.

public string Username { get; }

Property Value

string

VerifySslCertificate

Gets a value indicating whether to verify an SSL certificate.

[Obsolete("Use AllowInsecureTls instead.")]
public bool VerifySslCertificate { get; }

Property Value

bool

W

Gets the W component of the write concern.

public WriteConcern.WValue W { get; }

Property Value

WriteConcern.WValue

WTimeout

Gets the WTimeout component of the write concern.

public TimeSpan? WTimeout { get; }

Property Value

TimeSpan?

WaitQueueMultiple

Gets the wait queue multiple (the actual wait queue size will be WaitQueueMultiple x MaxConnectionPoolSize).

[Obsolete("This property will be removed in a later release.")]
public double WaitQueueMultiple { get; }

Property Value

double

WaitQueueSize

Gets the wait queue size.

[Obsolete("This property will be removed in a later release.")]
public int WaitQueueSize { get; }

Property Value

int

WaitQueueTimeout

Gets the wait queue timeout.

public TimeSpan WaitQueueTimeout { get; }

Property Value

TimeSpan

Methods

ClearCache()

Clears the URL cache. When a URL is parsed it is stored in the cache so that it doesn't have to be parsed again. There is rarely a need to call this method.

public static void ClearCache()

Create(string)

Creates an instance of MongoUrl (might be an existing existence if the same URL has been used before).

public static MongoUrl Create(string url)

Parameters

url string

The URL containing the settings.

Returns

MongoUrl

An instance of MongoUrl.

Equals(MongoUrl)

Compares two MongoUrls.

public bool Equals(MongoUrl rhs)

Parameters

rhs MongoUrl

The other URL.

Returns

bool

True if the two URLs are equal.

Equals(object)

Compares two MongoUrls.

public override bool Equals(object obj)

Parameters

obj object

The other URL.

Returns

bool

True if the two URLs are equal.

GetCredential()

Gets the credential.

public MongoCredential GetCredential()

Returns

MongoCredential

The credential (or null if the URL has not authentication settings).

GetHashCode()

Gets the hash code.

public override int GetHashCode()

Returns

int

The hash code.

GetWriteConcern(bool)

Returns a WriteConcern value based on this instance's settings and a default enabled value.

public WriteConcern GetWriteConcern(bool enabledDefault)

Parameters

enabledDefault bool

The default enabled value.

Returns

WriteConcern

A WriteConcern.

Resolve(bool, CancellationToken)

Resolves a connection string. If the connection string indicates more information is available in the DNS system, it will acquire that information as well.

public MongoUrl Resolve(bool resolveHosts, CancellationToken cancellationToken = default)

Parameters

resolveHosts bool

Whether to resolve hosts.

cancellationToken CancellationToken

The cancellation token.

Returns

MongoUrl

A resolved MongoURL.

Resolve(CancellationToken)

Resolves a connection string. If the connection string indicates more information is available in the DNS system, it will acquire that information as well.

public MongoUrl Resolve(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

MongoUrl

A resolved MongoURL.

ResolveAsync(bool, CancellationToken)

Resolves a connection string. If the connection string indicates more information is available in the DNS system, it will acquire that information as well.

public Task<MongoUrl> ResolveAsync(bool resolveHosts, CancellationToken cancellationToken = default)

Parameters

resolveHosts bool

Whether to resolve hosts.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<MongoUrl>

A resolved MongoURL.

ResolveAsync(CancellationToken)

Resolves a connection string. If the connection string indicates more information is available in the DNS system, it will acquire that information as well.

public Task<MongoUrl> ResolveAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation token.

Returns

Task<MongoUrl>

A resolved MongoURL.

ToString()

Returns the canonical URL based on the settings in this MongoUrlBuilder.

public override string ToString()

Returns

string

The canonical URL.

Operators

operator ==(MongoUrl, MongoUrl)

Compares two MongoUrls.

public static bool operator ==(MongoUrl lhs, MongoUrl rhs)

Parameters

lhs MongoUrl

The first URL.

rhs MongoUrl

The other URL.

Returns

bool

True if the two URLs are equal (or both null).

operator !=(MongoUrl, MongoUrl)

Compares two MongoUrls.

public static bool operator !=(MongoUrl lhs, MongoUrl rhs)

Parameters

lhs MongoUrl

The first URL.

rhs MongoUrl

The other URL.

Returns

bool

True if the two URLs are not equal (or one is null and the other is not).