CatapultServer  v0.5.0.1 (Elephant)
MongoDatabase.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include <bsoncxx/builder/stream/array.hpp>
23 #include <bsoncxx/builder/stream/document.hpp>
24 #include <mongocxx/client.hpp>
25 #include <mongocxx/pool.hpp>
26 #include <string>
27 
28 namespace catapult { namespace mongo {
29 
31  class MongoDatabase {
32  public:
34  explicit MongoDatabase(mongocxx::pool& connectionPool, const std::string& databaseName)
35  : m_pConnection(connectionPool.acquire())
36  , m_database(m_pConnection->database(databaseName))
37  {}
38 
39  public:
41  operator const mongocxx::database&() const {
42  return m_database;
43  }
44 
46  operator mongocxx::database&() {
47  return m_database;
48  }
49 
51  const mongocxx::collection operator[](const std::string& collectionName) const {
52  return m_database[collectionName];
53  }
54 
56  mongocxx::collection operator[](const std::string& collectionName) {
57  return m_database[collectionName];
58  }
59 
60  private:
61  mongocxx::pool::entry m_pConnection;
62  mongocxx::database m_database;
63  };
64 }}
catapult::mongo::MongoDatabase::m_database
mongocxx::database m_database
Definition: MongoDatabase.h:62
catapult::mongo::MongoDatabase::operator[]
mongocxx::collection operator[](const std::string &collectionName)
Gets the mongocxx collection with name collectionName.
Definition: MongoDatabase.h:56
catapult::mongo::MongoDatabase::operator[]
const mongocxx::collection operator[](const std::string &collectionName) const
Gets the const mongocxx collection with name collectionName.
Definition: MongoDatabase.h:51
catapult::mongo::MongoDatabase::m_pConnection
mongocxx::pool::entry m_pConnection
Definition: MongoDatabase.h:61
catapult::mongo::MongoDatabase::MongoDatabase
MongoDatabase(mongocxx::pool &connectionPool, const std::string &databaseName)
Creates a mongo database around connectionPool and databaseName.
Definition: MongoDatabase.h:34
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::mongo::MongoDatabase
Represents a mongo database.
Definition: MongoDatabase.h:31