Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::database::MongoClient Class Reference

An asynchronous MongoDB client using coroutines. More...

#include <MongoClient.hpp>

Collaboration diagram for orbit::database::MongoClient:

Classes

struct  Config
 Configuration options for the MongoDB client. More...
 
struct  InsertAwaiter
 
struct  QueryAwaiter
 
struct  QueryResult
 

Public Member Functions

 MongoClient (concurrency::ThreadPool &thread_pool, const Config &config)
 Constructs a new MongoClient.
 
 ~MongoClient ()
 
 MongoClient (const MongoClient &)=delete
 
MongoClient & operator= (const MongoClient &)=delete
 
QueryAwaiter find_async (std::string query_json)
 Executes a find query asynchronously.
 
InsertAwaiter insert_async (std::string doc_json)
 Inserts a document asynchronously.
 
concurrency::ThreadPool & get_thread_pool ()
 Gets the associated thread pool.
 
mongoc_client_pool_t * get_pool ()
 Gets the underlying MongoDB client pool.
 
const Config & get_config () const
 Gets the configuration used by this client.
 

Private Attributes

concurrency::ThreadPool & thread_pool_
 
Config config_
 
mongoc_uri_t * uri_ {nullptr}
 
mongoc_client_pool_t * pool_ {nullptr}
 

Detailed Description

An asynchronous MongoDB client using coroutines.

Constructor & Destructor Documentation

◆ MongoClient() [1/2]

orbit::database::MongoClient::MongoClient ( concurrency::ThreadPool &  thread_pool,
const Config &  config 
)

Constructs a new MongoClient.

Parameters
thread_poolThe thread pool to use for asynchronous operations.
configThe configuration settings for the MongoDB client.

◆ ~MongoClient()

orbit::database::MongoClient::~MongoClient ( )

◆ MongoClient() [2/2]

orbit::database::MongoClient::MongoClient ( const MongoClient &  )
delete

Member Function Documentation

◆ find_async()

QueryAwaiter orbit::database::MongoClient::find_async ( std::string  query_json)

Executes a find query asynchronously.

Parameters
query_jsonThe JSON string representing the query.
Returns
A QueryAwaiter that can be co_awaited for the result.
auto result = co_await client.find_async("{\"name\": \"test\"}");

◆ get_config()

const Config & orbit::database::MongoClient::get_config ( ) const
inline

Gets the configuration used by this client.

Returns
Constant reference to the configuration.

◆ get_pool()

mongoc_client_pool_t * orbit::database::MongoClient::get_pool ( )
inline

Gets the underlying MongoDB client pool.

Returns
Pointer to the mongoc_client_pool_t instance.

◆ get_thread_pool()

concurrency::ThreadPool & orbit::database::MongoClient::get_thread_pool ( )
inline

Gets the associated thread pool.

Returns
Reference to the thread pool.

◆ insert_async()

InsertAwaiter orbit::database::MongoClient::insert_async ( std::string  doc_json)

Inserts a document asynchronously.

Parameters
doc_jsonThe JSON string representing the document to insert.
Returns
An InsertAwaiter that can be co_awaited for success status.

◆ operator=()

MongoClient & orbit::database::MongoClient::operator= ( const MongoClient &  )
delete

Member Data Documentation

◆ config_

Config orbit::database::MongoClient::config_
private

◆ pool_

mongoc_client_pool_t* orbit::database::MongoClient::pool_ {nullptr}
private

◆ thread_pool_

concurrency::ThreadPool& orbit::database::MongoClient::thread_pool_
private

◆ uri_

mongoc_uri_t* orbit::database::MongoClient::uri_ {nullptr}
private

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