Table of Contents

Class MongoServer

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.Legacy.dll

Represents a MongoDB server (either a single instance or a replica set) and the settings used to access it. This class is thread-safe.

public class MongoServer
Inheritance
MongoServer
Inherited Members
Extension Methods

Constructors

MongoServer(MongoServerSettings)

Creates a new instance of MongoServer. Normally you will use one of the Create methods instead of the constructor to create instances of this class.

Properties

Arbiters

Gets the arbiter instances.

Instance

Gets the one and only instance for this server.

Instances

Gets the instances for this server.

this[string]

Gets a MongoDatabase instance representing a database on this server.

this[string, WriteConcern]

Gets a MongoDatabase instance representing a database on this server.

MaxServerCount

Gets or sets the maximum number of instances of MongoServer that will be allowed to be created.

MaxWireVersion

Gets the maximum wire version.

Passives

Gets the passive instances.

Primary

Gets the primary instance (null if there is no primary).

ReplicaSetName

Gets the name of the replica set (null if not connected to a replica set).

Secondaries

Gets the secondary instances.

SequentialId

Gets the unique sequential Id for this server.

ServerCount

Gets the number of instances of MongoServer that have been created.

Settings

Gets the settings for this server.

State

Gets the current state of this server (as of the last operation, not updated until another operation is performed).

Methods

Connect()

Connects to the server. Normally there is no need to call this method as the driver will connect to the server automatically when needed.

Connect(TimeSpan)

Connects to the server. Normally there is no need to call this method as the driver will connect to the server automatically when needed.

DatabaseExists(string)

Tests whether a database exists.

Disconnect()

Disconnects from the server. Normally there is no need to call this method so you should be sure to have a good reason to call it.

DropDatabase(string)

Drops a database.

FetchDBRef(MongoDBRef)

Fetches the document referred to by the DBRef.

FetchDBRefAs(Type, MongoDBRef)

Fetches the document referred to by the DBRef.

FetchDBRefAs<TDocument>(MongoDBRef)

Fetches the document referred to by the DBRef, deserialized as a TDocument.

GetAllServers()

Gets an array containing a snapshot of the set of all servers that have been created so far.

GetDatabase(string)

Gets a MongoDatabase instance representing a database on this server.

GetDatabase(string, MongoDatabaseSettings)

Gets a MongoDatabase instance representing a database on this server.

GetDatabase(string, WriteConcern)

Gets a MongoDatabase instance representing a database on this server.

GetDatabaseNames()

Gets the names of the databases on this server.

GetServerInstance(MongoServerAddress)

Gets the server instance.

IsDatabaseNameValid(string, out string)

Checks whether a given database name is valid on this server.

Ping()

Checks whether the server is alive (throws an exception if not). If server is a replica set, pings all members one at a time.

Reconnect()

Reconnects to the server. Normally there is no need to call this method. All connections are closed and new connections will be opened as needed. Calling this method frequently will result in connection thrashing.

UnregisterAllServers()

Unregisters all servers from the dictionary used by Create to remember which servers have already been created.

UnregisterServer(MongoServer)

Unregisters a server from the dictionary used by Create to remember which servers have already been created.

WithReadConcern(ReadConcern)

Returns a new MongoServer instance with a different read concern setting.

WithReadPreference(ReadPreference)

Returns a new MongoServer instance with a different read preference setting.

WithWriteConcern(WriteConcern)

Returns a new MongoServer instance with a different write concern setting.