Class MongoDatabase
Represents a MongoDB database and the settings used to access it. This class is thread-safe.
public class MongoDatabase
- Inheritance
-
MongoDatabase
- Inherited Members
- Extension Methods
Constructors
- MongoDatabase(MongoServer, string, MongoDatabaseSettings)
Creates a new instance of MongoDatabase. Normally you would call one of the indexers or GetDatabase methods of MongoServer instead.
Properties
- CommandCollection
Gets the command collection for this database.
- GridFS
Gets the default GridFS instance for this database. The default GridFS instance uses default GridFS settings. See also GetGridFS if you need to use GridFS with custom settings.
- this[string]
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- this[string, WriteConcern]
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- Name
Gets the name of this database.
- Server
Gets the server that contains this database.
- Settings
Gets the settings being used to access this database.
Methods
- AddUser(MongoUser)
Adds a user to this database.
- CollectionExists(string)
Tests whether a collection exists on this database.
- CreateCollection(string)
Creates a collection. MongoDB creates collections automatically when they are first used, so this command is mainly here for frameworks.
- CreateCollection(string, IMongoCollectionOptions)
Creates a collection. MongoDB creates collections automatically when they are first used, so you only need to call this method if you want to provide non-default options.
- Drop()
Drops a database.
- DropCollection(string)
Drops a collection.
- Eval(BsonJavaScript, params object[])
Evaluates JavaScript code at the server.
- Eval(EvalArgs)
Evaluates JavaScript code at the server.
- Eval(EvalFlags, BsonJavaScript, params object[])
Evaluates JavaScript code at the server.
- 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
.
- FindAllUsers()
Finds all users of this database.
- FindUser(string)
Finds a user of this database.
- GetCollection(string)
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- GetCollection(string, MongoCollectionSettings)
Gets a MongoCollection instance representing a collection on this database with a default document type of TDefaultDocument.
- GetCollection(string, WriteConcern)
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- GetCollection(Type, string)
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- GetCollection(Type, string, MongoCollectionSettings)
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- GetCollection(Type, string, WriteConcern)
Gets a MongoCollection instance representing a collection on this database with a default document type of BsonDocument.
- GetCollectionNames()
Gets a list of the names of all the collections in this database.
- GetCollection<TDefaultDocument>(string)
Gets a MongoCollection instance representing a collection on this database with a default document type of TDefaultDocument.
- GetCollection<TDefaultDocument>(string, MongoCollectionSettings)
Gets a MongoCollection instance representing a collection on this database with a default document type of TDefaultDocument.
- GetCollection<TDefaultDocument>(string, WriteConcern)
Gets a MongoCollection instance representing a collection on this database with a default document type of TDefaultDocument.
- GetCurrentOp()
Gets the current operation.
- GetGridFS(MongoGridFSSettings)
Gets an instance of MongoGridFS for this database using custom GridFS settings.
- GetProfilingInfo(IMongoQuery)
Gets one or more documents from the system.profile collection.
- GetProfilingLevel()
Gets the current profiling level.
- GetSisterDatabase(string)
Gets a sister database on the same server.
- GetStats()
Gets the current database stats.
- IsCollectionNameValid(string, out string)
Checks whether a given collection name is valid in this database.
- RemoveUser(MongoUser)
Removes a user from this database.
- RemoveUser(string)
Removes a user from this database.
- RenameCollection(string, string)
Renames a collection on this database.
- RenameCollection(string, string, bool)
Renames a collection on this database.
- RunCommand(IMongoCommand)
Runs a command on this database.
- RunCommand(string)
Runs a command on this database.
- RunCommandAs(Type, IMongoCommand)
Runs a command on this database and returns the result as a TCommandResult.
- RunCommandAs(Type, string)
Runs a command on this database and returns the result as a TCommandResult.
- RunCommandAs<TCommandResult>(IMongoCommand)
Runs a command on this database and returns the result as a TCommandResult.
- RunCommandAs<TCommandResult>(IMongoCommand, ReadPreference)
Runs a command on this database and returns the result as a TCommandResult.
- RunCommandAs<TCommandResult>(string)
Runs a command on this database and returns the result as a TCommandResult.
- SetProfilingLevel(ProfilingLevel)
Sets the level of profile information to write.
- SetProfilingLevel(ProfilingLevel, TimeSpan)
Sets the level of profile information to write.
- ToString()
Gets a canonical string representation for this database.
- WithReadConcern(ReadConcern)
Returns a new MongoDatabase instance with a different read concern setting.
- WithReadPreference(ReadPreference)
Returns a new MongoDatabase instance with a different read preference setting.
- WithWriteConcern(WriteConcern)
Returns a new MongoDatabase instance with a different write concern setting.