Qore mongodb Module 2.3.0
Loading...
Searching...
No Matches
mongodb::MongoDatabase Class Reference

The MongoDatabase class provides MongoDB database operations. More...

#include <QC_MongoDatabase.dox.h>

Public Member Methods

MongoCollection createCollection (string name)
 Creates a new collection in this database.
 
bool drop ()
 Drops this database.
 
MongoCollection getCollection (string name)
 Returns a MongoCollection object for the given collection name.
 
*string getName ()
 Returns the name of this database.
 
list< string > listCollectionNames ()
 Returns a list of collection names in this database.
 
hash< auto > runCommand (hash< auto > command)
 Runs a command on this database.
 

Detailed Description

The MongoDatabase class provides MongoDB database operations.

This class represents a MongoDB database and provides methods for collection management and database-level operations.

Example:
# Get a database from a client
MongoDatabase db = client.getDatabase("mydb");
# List collections
list<string> colls = db.listCollectionNames();
# Get a collection
MongoCollection coll = db.getCollection("users");
# Run a command
hash<auto> result = db.runCommand({"ping": 1});
Since
mongodb 1.0

Member Function Documentation

◆ createCollection()

MongoCollection mongodb::MongoDatabase::createCollection ( string  name)

Creates a new collection in this database.

Parameters
namethe collection name
Returns
a MongoCollection object for the new collection
Example:
MongoCollection coll = db.createCollection("newcollection");
Exceptions
MONGODB-DATABASE-ERRORfailed to create collection

◆ drop()

bool mongodb::MongoDatabase::drop ( )

Drops this database.

Returns
True if the database was dropped successfully
Example:
if (db.drop()) {
print("Database dropped\n");
}
Exceptions
MONGODB-DATABASE-ERRORfailed to drop database

◆ getCollection()

MongoCollection mongodb::MongoDatabase::getCollection ( string  name)

Returns a MongoCollection object for the given collection name.

Parameters
namethe collection name
Returns
a MongoCollection object
Example:
MongoCollection coll = db.getCollection("users");

◆ getName()

*string mongodb::MongoDatabase::getName ( )

Returns the name of this database.

Returns
the database name
Code Flags:
CONSTANT
Example:
string name = db.getName();

◆ listCollectionNames()

list< string > mongodb::MongoDatabase::listCollectionNames ( )

Returns a list of collection names in this database.

Returns
a list of collection names
Example:
list<string> colls = db.listCollectionNames();
foreach string coll in (colls) {
printf("Collection: %s\n", coll);
}
Exceptions
MONGODB-DATABASE-ERRORfailed to list collections

◆ runCommand()

hash< auto > mongodb::MongoDatabase::runCommand ( hash< auto >  command)

Runs a command on this database.

Parameters
commandthe command document
Returns
the command result
Example:
hash<auto> result = db.runCommand({"ping": 1});
hash<auto> stats = db.runCommand({"dbStats": 1});
Exceptions
MONGODB-DATABASE-ERRORcommand failed

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