The MongoDatabase class provides MongoDB database operations.
More...
#include <QC_MongoDatabase.dox.h>
The MongoDatabase class provides MongoDB database operations.
This class represents a MongoDB database and provides methods for collection management and database-level operations.
- Example:
MongoDatabase db = client.getDatabase("mydb");
list<string> colls = db.listCollectionNames();
MongoCollection coll = db.getCollection("users");
hash<auto> result = db.runCommand({"ping": 1});
- Since
- mongodb 1.0
◆ createCollection()
Creates a new collection in this database.
- Parameters
-
- Returns
- a MongoCollection object for the new collection
- Example:
MongoCollection coll = db.createCollection("newcollection");
- Exceptions
-
| MONGODB-DATABASE-ERROR | failed 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-ERROR | failed to drop database |
◆ getCollection()
Returns a MongoCollection object for the given collection name.
- Parameters
-
- 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-ERROR | failed to list collections |
◆ runCommand()
| hash< auto > mongodb::MongoDatabase::runCommand |
( |
hash< auto > |
command | ) |
|
Runs a command on this database.
- Parameters
-
| command | the command document |
- Returns
- the command result
- Example:
hash<auto> result = db.runCommand({"ping": 1});
hash<auto> stats = db.runCommand({"dbStats": 1});
- Exceptions
-
| MONGODB-DATABASE-ERROR | command failed |
The documentation for this class was generated from the following file: