Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
mongo_fetch.hpp
Go to the documentation of this file.
1/*
2 __ __ _____ _ _
3 | \/ | ___ _ __ __ _ ___ | ___|__| |_ ___| |__
4 | |\/| |/ _ \| '_ \ / _` |/ _ \| |_ / _ \ __/ __| '_ \
5 | | | | (_) | | | | (_| | (_) | _| __/ || (__| | | |
6 |_| |_|\___/|_| |_|\__, |\___/|_| \___|\__\___|_| |_|
7 |___/
8Paolo Bosetti, 2026
9Fetches data from multiple MongoDB collections and prepare for replay by
10merging them into a single view sorted by timestamp, also providing the time
11difference between records.
12*/
13#pragma once
14
15#include <chrono>
16#include <memory>
17#include <string>
18#include <vector>
19
20#include <nlohmann/json.hpp>
21
22namespace Mads {
23
32public:
37 explicit MongoFetch(const std::string &uri);
38
46
47 MongoFetch(const MongoFetch &) = delete;
48 MongoFetch &operator=(const MongoFetch &) = delete;
49 MongoFetch(MongoFetch &&) noexcept;
50 MongoFetch &operator=(MongoFetch &&) noexcept;
51
55 void connect();
56
63 void disconnect();
64
69 void select_database(const std::string &db_name);
70
75 void select_collections(const std::vector<std::string> &collections);
76
82 void select_time_range(const std::string &start, const std::string &end);
83
88 void select_time_range(const std::string &start);
89
105 std::size_t fetch_data();
106
124 std::size_t fetch_data(std::string &view_name);
125
135 std::size_t fetch_data(const std::string &view_name);
136
146 std::size_t fetch_data_from(const std::string &view_name);
147
152 void set_repeat(bool repeat);
153
164 std::chrono::milliseconds load_next(nlohmann::json &out, std::string &collection_name);
165
171 void set_unwrap_original(bool unwrap);
172
173private:
174 struct Impl;
175 std::unique_ptr<Impl> _impl;
176};
177
178} // namespace Mads
Replay reader over one or more MongoDB collections.
MongoFetch(MongoFetch &&) noexcept
void set_unwrap_original(bool unwrap)
Set whether to unwrap the original document.
MongoFetch(const MongoFetch &)=delete
void select_database(const std::string &db_name)
Select the database on which to operate.
std::size_t fetch_data_from(const std::string &view_name)
Reuse an existing persistent replay view.
void set_repeat(bool repeat)
Set whether replay restarts from the beginning after the last record.
MongoFetch & operator=(const MongoFetch &)=delete
void disconnect()
Close the connection to the MongoDB server and clear replay state.
~MongoFetch()
Destroy the fetcher instance.
MongoFetch(const std::string &uri)
Construct a fetcher bound to the specified MongoDB URI.
std::size_t fetch_data()
Create a replay view over the selected MongoDB data.
std::chrono::milliseconds load_next(nlohmann::json &out, std::string &collection_name)
Load the next record from the replay view.
void select_time_range(const std::string &start, const std::string &end)
Select the time range of interest.
void select_collections(const std::vector< std::string > &collections)
Define the list of collections to fetch data from.
void connect()
Open the connection to the MongoDB server.
Definition agent.hpp:67
nlohmann::json json