Storage Engine API
mongo::Database Class Reference

Represents a logical database containing Collections. More...

#include <database.h>

Inheritance diagram for mongo::Database:

Detailed Description

Represents a logical database containing Collections.

The semantics for a const Database are that you can mutate individual collections but not add or remove them.

Classes

class  Impl
 
class  iterator
 Iterating over a Database yields Collection* pointers. More...
 
struct  TUHook
 

Public Types

typedef StringMap< Collection * > CollectionMap
 

Public Member Functions

 Database (OperationContext *const opCtx, const StringData name, DatabaseCatalogEntry *const dbEntry)
 
 ~Database ()=default
 
 Database (Database &&)=delete
 
Databaseoperator= (Database &&)=delete
 
iterator begin () const
 
iterator end () const
 
void close (OperationContext *const opCtx, const std::string &reason)
 
const std::string & name () const
 
void clearTmpCollections (OperationContext *const opCtx)
 
Status setProfilingLevel (OperationContext *const opCtx, const int newLevel)
 Sets a new profiling level for the database and returns the outcome. More...
 
int getProfilingLevel () const
 
const char * getProfilingNS () const
 
void setDropPending (OperationContext *opCtx, bool dropPending)
 Sets the 'drop-pending' state of this Database. More...
 
bool isDropPending (OperationContext *opCtx) const
 Returns the 'drop-pending' state of this Database. More...
 
void getStats (OperationContext *const opCtx, BSONObjBuilder *const output, const double scale=1)
 
const DatabaseCatalogEntrygetDatabaseCatalogEntry () const
 
Status dropCollection (OperationContext *const opCtx, const StringData fullns, repl::OpTime dropOpTime={})
 dropCollection() will refuse to drop system collections. More...
 
Status dropCollectionEvenIfSystem (OperationContext *const opCtx, const NamespaceString &fullns, repl::OpTime dropOpTime={})
 
Status dropView (OperationContext *const opCtx, const StringData fullns)
 
CollectioncreateCollection (OperationContext *const opCtx, StringData ns, const CollectionOptions &options=CollectionOptions(), const bool createDefaultIndexes=true, const BSONObj &idIndex=BSONObj())
 
Status createView (OperationContext *const opCtx, const StringData viewName, const CollectionOptions &options)
 
CollectiongetCollection (OperationContext *opCtx, const StringData ns) const
 
CollectiongetCollection (OperationContext *opCtx, const NamespaceString &ns) const
 
ViewCatalog * getViewCatalog ()
 Get the view catalog, which holds the definition for all views created on this database. More...
 
CollectiongetOrCreateCollection (OperationContext *const opCtx, const NamespaceString &nss)
 
Status renameCollection (OperationContext *const opCtx, const StringData fromNS, const StringData toNS, const bool stayTemp)
 
const NamespaceString & getSystemIndexesName () const
 
const std::string & getSystemViewsName () const
 
StatusWith< NamespaceString > makeUniqueCollectionNamespace (OperationContext *opCtx, StringData collectionNameModel)
 Generates a collection namespace suitable for creating a temporary collection. More...
 

Static Public Member Functions

static MONGO_DECLARE_SHIM ((OperationContext *opCtx) ->void) dropAllDatabasesExceptLocal
 
static MONGO_DECLARE_SHIM ((OperationContext *opCtx, Database *db, StringData ns, BSONObj options, CollectionOptions::ParseKind parseKind=CollectionOptions::parseForCommand, bool createDefaultIndexes=true, const BSONObj &idIndex=BSONObj()) ->Status) userCreateNS
 Creates the namespace 'ns' in the database 'db' according to 'options'. More...
 
static MONGO_DECLARE_SHIM ((Database *this_, OperationContext *opCtx, StringData name, DatabaseCatalogEntry *, PrivateTo< Database >) ->std::unique_ptr< Impl >) makeImpl
 
static MONGO_DECLARE_SHIM ((OperationContext *opCtx, Database *db) ->void) dropDatabase
 Physically drops the specified opened database and removes it from the server's metadata. More...
 

Private Member Functions

const Impl_impl () const
 
Impl_impl ()
 

Private Attributes

std::unique_ptr< Impl_pimpl
 

Member Typedef Documentation

◆ CollectionMap

Constructor & Destructor Documentation

◆ Database() [1/2]

mongo::Database::Database ( OperationContext *const  opCtx,
const StringData  name,
DatabaseCatalogEntry *const  dbEntry 
)
inlineexplicit

◆ ~Database()

mongo::Database::~Database ( )
inlinedefault

◆ Database() [2/2]

mongo::Database::Database ( Database &&  )
inlinedelete

Member Function Documentation

◆ _impl() [1/2]

const Impl& mongo::Database::_impl ( ) const
inlineprivate

◆ _impl() [2/2]

Impl& mongo::Database::_impl ( )
inlineprivate

◆ begin()

iterator mongo::Database::begin ( ) const
inline

◆ clearTmpCollections()

void mongo::Database::clearTmpCollections ( OperationContext *const  opCtx)
inline

◆ close()

void mongo::Database::close ( OperationContext *const  opCtx,
const std::string &  reason 
)
inline

◆ createCollection()

Collection* mongo::Database::createCollection ( OperationContext *const  opCtx,
StringData  ns,
const CollectionOptions options = CollectionOptions(),
const bool  createDefaultIndexes = true,
const BSONObj &  idIndex = BSONObj() 
)
inline

◆ createView()

Status mongo::Database::createView ( OperationContext *const  opCtx,
const StringData  viewName,
const CollectionOptions options 
)
inline

◆ dropCollection()

Status mongo::Database::dropCollection ( OperationContext *const  opCtx,
const StringData  fullns,
repl::OpTime  dropOpTime = {} 
)
inline

dropCollection() will refuse to drop system collections.

Use dropCollectionEvenIfSystem() if that is required.

If we are applying a 'drop' oplog entry on a secondary, 'dropOpTime' will contain the optime of the oplog entry.

◆ dropCollectionEvenIfSystem()

Status mongo::Database::dropCollectionEvenIfSystem ( OperationContext *const  opCtx,
const NamespaceString &  fullns,
repl::OpTime  dropOpTime = {} 
)
inline

◆ dropView()

Status mongo::Database::dropView ( OperationContext *const  opCtx,
const StringData  fullns 
)
inline

◆ end()

iterator mongo::Database::end ( ) const
inline

◆ getCollection() [1/2]

Collection* mongo::Database::getCollection ( OperationContext *  opCtx,
const StringData  ns 
) const
inline
Parameters
ns- this is fully qualified, which is maybe not ideal ???

◆ getCollection() [2/2]

Collection* mongo::Database::getCollection ( OperationContext *  opCtx,
const NamespaceString &  ns 
) const
inline

◆ getDatabaseCatalogEntry()

const DatabaseCatalogEntry* mongo::Database::getDatabaseCatalogEntry ( ) const
inline

◆ getOrCreateCollection()

Collection* mongo::Database::getOrCreateCollection ( OperationContext *const  opCtx,
const NamespaceString &  nss 
)
inline

◆ getProfilingLevel()

int mongo::Database::getProfilingLevel ( ) const
inline

◆ getProfilingNS()

const char* mongo::Database::getProfilingNS ( ) const
inline

◆ getStats()

void mongo::Database::getStats ( OperationContext *const  opCtx,
BSONObjBuilder *const  output,
const double  scale = 1 
)
inline

◆ getSystemIndexesName()

const NamespaceString& mongo::Database::getSystemIndexesName ( ) const
inline

◆ getSystemViewsName()

const std::string& mongo::Database::getSystemViewsName ( ) const
inline

◆ getViewCatalog()

ViewCatalog* mongo::Database::getViewCatalog ( )
inline

Get the view catalog, which holds the definition for all views created on this database.

You must be holding a database lock to use this accessor.

◆ isDropPending()

bool mongo::Database::isDropPending ( OperationContext *  opCtx) const
inline

Returns the 'drop-pending' state of this Database.

The database must be locked in MODE_X when calling this function.

◆ makeUniqueCollectionNamespace()

StatusWith<NamespaceString> mongo::Database::makeUniqueCollectionNamespace ( OperationContext *  opCtx,
StringData  collectionNameModel 
)
inline

Generates a collection namespace suitable for creating a temporary collection.

The namespace is based on a model that replaces each percent sign in 'collectionNameModel' by a random character in the range [0-9A-Za-z]. Returns FailedToParse if 'collectionNameModel' does not contain any percent signs. Returns NamespaceExists if we are unable to generate a collection name that does not conflict with an existing collection in this database.

The database must be locked in MODE_X when calling this function.

◆ MONGO_DECLARE_SHIM() [1/4]

static mongo::Database::MONGO_DECLARE_SHIM ( (OperationContext *opCtx) ->  void)
static

◆ MONGO_DECLARE_SHIM() [2/4]

static mongo::Database::MONGO_DECLARE_SHIM ( (OperationContext *opCtx, Database *db, StringData ns, BSONObj options, CollectionOptions::ParseKind parseKind=CollectionOptions::parseForCommand, bool createDefaultIndexes=true, const BSONObj &idIndex=BSONObj()) ->  Status)
static

Creates the namespace 'ns' in the database 'db' according to 'options'.

If 'createDefaultIndexes' is true, creates the _id index for the collection (and the system indexes, in the case of system collections). Creates the collection's _id index according to 'idIndex', if it is non-empty. When 'idIndex' is empty, creates the default _id index.

◆ MONGO_DECLARE_SHIM() [3/4]

static mongo::Database::MONGO_DECLARE_SHIM ( (Database *this_, OperationContext *opCtx, StringData name, DatabaseCatalogEntry *, PrivateTo< Database >) ->std::unique_ptr< Impl )
static

◆ MONGO_DECLARE_SHIM() [4/4]

static mongo::Database::MONGO_DECLARE_SHIM ( (OperationContext *opCtx, Database *db) ->  void)
static

Physically drops the specified opened database and removes it from the server's metadata.

It doesn't notify the replication subsystem or do any other consistency checks, so it should not be used directly from user commands.

Must be called with the specified database locked in X mode.

◆ name()

const std::string& mongo::Database::name ( ) const
inline

◆ operator=()

Database& mongo::Database::operator= ( Database &&  )
inlinedelete

◆ renameCollection()

Status mongo::Database::renameCollection ( OperationContext *const  opCtx,
const StringData  fromNS,
const StringData  toNS,
const bool  stayTemp 
)
inline

◆ setDropPending()

void mongo::Database::setDropPending ( OperationContext *  opCtx,
bool  dropPending 
)
inline

Sets the 'drop-pending' state of this Database.

This is done at the beginning of a dropDatabase operation and is used to reject subsequent collection creation requests on this database. Throws a UserAssertion if this is called on a Database that is already in a 'drop-pending' state. The database must be locked in MODE_X when calling this function.

◆ setProfilingLevel()

Status mongo::Database::setProfilingLevel ( OperationContext *const  opCtx,
const int  newLevel 
)
inline

Sets a new profiling level for the database and returns the outcome.

Parameters
opCtxOperation context which to use for creating the profiling collection.
newLevelNew profiling level to use.

Member Data Documentation

◆ _pimpl

std::unique_ptr<Impl> mongo::Database::_pimpl
private

The documentation for this class was generated from the following file: