Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6aab904
feature(MongoDB): Initial implementation of support for replica sets.
matejk Nov 26, 2025
d5fe6db
enh(MongoDB): Add parsing of mongodb replica set URI.
matejk Nov 27, 2025
ef6a52a
enh(MongoDB): Treat single-server as primary, fix parsing of URI.
matejk Nov 27, 2025
4ef9955
fix(MongoDB): Add missing example for parsing the URI.
matejk Nov 27, 2025
ad10b5a
enh(MongoDB): simplified and modernised code.
matejk Nov 27, 2025
f089c53
fix(MongoDB): Fixes based on static analysis report.
matejk Nov 27, 2025
c467678
enh(MongoDB): Remove unused includes.
matejk Nov 27, 2025
abbae08
fix(MongoDB): ReplicaSetMonitor: handle wrong arguments more gracefully.
matejk Nov 28, 2025
767a06d
enh(MongoDB) Use string literals and char constants where possible.
matejk Nov 28, 2025
346c108
enh(MongoDB) More tests.
matejk Nov 29, 2025
b50dc3a
fix(MongoDB): Prevent duplicate entries in MongoDB::Document.
matejk Nov 29, 2025
9c4a8c4
enh(MongoDB): Update RS tests, remove support for pre 5.1 MongoDB.
matejk Nov 29, 2025
8f85a88
enh(MongoDB): Use C++ std mutex primitives instead of Poco.
matejk Nov 29, 2025
76c8fe7
fix(MongoDB): correct replica set compile errors.
matejk Nov 29, 2025
cffbf79
fix(MongoDB): fix replica set tests to work with IPv6 addresses.
matejk Nov 29, 2025
558ae6e
enh(MongoDB): Remove confusing hosts from ServerDescription and use h…
matejk Dec 1, 2025
e5b1014
enh(MongoDB): fix unused variables in tests.
matejk Dec 1, 2025
1309a02
enh(MongoDB): Add read-preference validation to replica set connectio…
matejk Dec 2, 2025
8bd992a
chore(MongoDB): Add reserve to Document.
matejk Dec 3, 2025
6e2b797
enh(MongoDB): connect to server in pool activateObject.
matejk Dec 3, 2025
de17263
chore(MongoDB): use tried servers set only locally inside executeWith…
matejk Dec 3, 2025
e11c981
enh(MongoDB): Add support for ReplicaSetConnection to OpMsgCursor.
matejk Dec 3, 2025
eff3bb2
enh(MongoDB): Replica set: More robust retry of failed MongoDB commands.
matejk Dec 4, 2025
0b491e1
enh(MongoDB): ReplicaSet remove redundant function, update documentat…
matejk Dec 4, 2025
ea48244
enh(MongoDB): Update handling of URL parameters.
matejk Dec 4, 2025
89eb135
enh(MongoDB): Updates to use SSL socket factory.
matejk Dec 4, 2025
7673ae9
enh(MongoDB): Log topology change when detected.
matejk Dec 4, 2025
e52a7b8
enh(MongoDB): Move function to wait for the server availability to Re…
matejk Dec 5, 2025
23a90b8
enh(MongoDB): Replica set: send notification on topology change.
matejk Dec 5, 2025
977f1d9
enh(MongoDB): Replica set: Remove internal logger for
matejk Dec 5, 2025
0b117db
enh(MongoDB): Replica set: Remove internal logger for topology change…
matejk Dec 5, 2025
98d6fd1
enh(MongoDB): Update samples and replica set readme.
matejk Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ endif()

# - resolve dependencies

if(ENABLE_SAMPLES)
set(ENABLE_UTIL ON CACHE BOOL "Enable Util" FORCE)
set(ENABLE_JSON ON CACHE BOOL "Enable JSON" FORCE)
set(ENABLE_XML ON CACHE BOOL "Enable XML" FORCE)
endif()

if(ENABLE_ENCODINGS_COMPILER)
set(ENABLE_NET ON CACHE BOOL "Enable Net" FORCE)
set(ENABLE_UTIL ON CACHE BOOL "Enable Util" FORCE)
Expand Down
5 changes: 2 additions & 3 deletions MongoDB/include/Poco/MongoDB/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Array class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -110,7 +110,6 @@ struct ElementTraits<Array::Ptr>

static std::string toString(const Array::Ptr& value, int indent = 0)
{
//TODO:
return value.isNull() ? "null" : value->toString(indent);
}
};
Expand All @@ -124,7 +123,7 @@ inline void BSONReader::read<Array::Ptr>(Array::Ptr& to)


template<>
inline void BSONWriter::write<Array::Ptr>(Array::Ptr& from)
inline void BSONWriter::write<Array::Ptr>(const Array::Ptr& from)
{
from->write(_writer);
}
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/BSONReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the BSONReader class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down
6 changes: 3 additions & 3 deletions MongoDB/include/Poco/MongoDB/BSONWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the BSONWriter class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -42,7 +42,7 @@ class MongoDB_API BSONWriter
}

template<typename T>
void write(T& t)
void write(const T& t)
/// Writes the value to the writer. The default implementation uses
/// the << operator. Special types can write their own version.
{
Expand All @@ -64,7 +64,7 @@ class MongoDB_API BSONWriter
inline void BSONWriter::writeCString(const std::string& value)
{
_writer.writeRaw(value);
_writer << (unsigned char) 0x00;
_writer << static_cast<unsigned char>(0x00);
}


Expand Down
24 changes: 18 additions & 6 deletions MongoDB/include/Poco/MongoDB/Binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Binary class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -58,15 +58,21 @@ class MongoDB_API Binary
Binary(const UUID& uuid);
/// Creates a Binary containing an UUID.

Binary(const char* data, unsigned char subtype = 0);
/// Creates a Binary with the contents of the given C-string and the given subtype.

Binary(const std::string& data, unsigned char subtype = 0);
/// Creates a Binary with the contents of the given string and the given subtype.

Binary(const void* data, Poco::Int32 size, unsigned char subtype = 0);
Binary(const void* data, Poco::Int32 size, unsigned char subtype);
/// Creates a Binary with the contents of the given buffer and the given subtype.

virtual ~Binary();
/// Destroys the Binary.

const Buffer<unsigned char>& buffer() const;
/// Returns a reference to the internal buffer

Buffer<unsigned char>& buffer();
/// Returns a reference to the internal buffer

Expand Down Expand Up @@ -110,6 +116,12 @@ inline void Binary::subtype(unsigned char type)
}


inline const Buffer<unsigned char>& Binary::buffer() const
{
return _buffer;
}


inline Buffer<unsigned char>& Binary::buffer()
{
return _buffer;
Expand Down Expand Up @@ -148,16 +160,16 @@ inline void BSONReader::read<Binary::Ptr>(Binary::Ptr& to)
_reader >> subtype;
to->subtype(subtype);

_reader.readRaw((char*) to->buffer().begin(), size);
_reader.readRaw(reinterpret_cast<char*>(to->buffer().begin()), size);
}


template<>
inline void BSONWriter::write<Binary::Ptr>(Binary::Ptr& from)
inline void BSONWriter::write<Binary::Ptr>(const Binary::Ptr& from)
{
_writer << (Poco::Int32) from->buffer().size();
_writer << static_cast<Poco::Int32>(from->buffer().size());
_writer << from->subtype();
_writer.writeRaw(reinterpret_cast<char*>(from->buffer().begin()), from->buffer().size());
_writer.writeRaw(reinterpret_cast<const char*>(from->buffer().begin()), from->buffer().size());
}


Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Connection class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down
2 changes: 1 addition & 1 deletion MongoDB/include/Poco/MongoDB/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Database class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down
61 changes: 18 additions & 43 deletions MongoDB/include/Poco/MongoDB/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Document class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand All @@ -22,7 +22,6 @@
#include "Poco/BinaryWriter.h"
#include "Poco/MongoDB/MongoDB.h"
#include "Poco/MongoDB/Element.h"
#include <algorithm>
#include <cstdlib>
#include <unordered_map>
#include <type_traits>
Expand Down Expand Up @@ -98,6 +97,9 @@ class MongoDB_API Document
return addElement(new ConcreteElement<T>(std::move(name), value));
}

void reserve(std::size_t size);
/// Reserves space for elements.

Document& add(const std::string& name, const char* value)
/// Creates an element with the given name and value and
/// adds it to the document.
Expand Down Expand Up @@ -213,34 +215,26 @@ class MongoDB_API Document
[[nodiscard]] virtual std::string toString(int indent = 0) const;
/// Returns a String representation of the document.

void write(BinaryWriter& writer);
void write(BinaryWriter& writer) const;
/// Writes a document to the reader

protected:
const ElementSet& elements() const noexcept;
/// Returns const reference to elements for read-only access by derived classes.
const std::vector<std::string>& orderedNames() const noexcept;
/// Returns const reference to element names in insertion order for read-only access by derived classes.
/// Direct modification is not allowed to maintain synchronization with hash map.

private:
ElementSet _elements;
std::vector<std::string> _elementNames;
/// Vector of element names in insertion order.
std::unordered_map<std::string, Element::Ptr> _elementMap;
/// Hash map for O(1) element lookups by name.
/// Maintained in sync with _elements for fast access.
/// These are private to ensure derived classes cannot break synchronization.
/// Maintained in sync with _elementNames for ordered access.
};


//
// inlines
//
inline Document& Document::addElement(Element::Ptr element)
{
_elements.push_back(element);
_elementMap[element->name()] = element; // O(1) insert for fast lookups
return *this;
}


inline Document& Document::addNewDocument(const std::string& name)
{
Document::Ptr newDoc = new Document();
Expand All @@ -251,24 +245,21 @@ inline Document& Document::addNewDocument(const std::string& name)

inline void Document::clear() noexcept
{
_elements.clear();
_elementNames.clear();
_elementMap.clear();
}


inline bool Document::empty() const noexcept
{
return _elements.empty();
return _elementNames.empty();
}


inline void Document::elementNames(std::vector<std::string>& keys) const
{
keys.reserve(keys.size() + _elements.size()); // Pre-allocate to avoid reallocations
for (const auto & _element : _elements)
{
keys.push_back(_element->name());
}
keys.reserve(keys.size() + _elementNames.size()); // Pre-allocate to avoid reallocations
keys.insert(keys.end(), _elementNames.begin(), _elementNames.end());
}


Expand All @@ -279,33 +270,17 @@ inline bool Document::exists(const std::string& name) const noexcept
}


inline bool Document::remove(const std::string& name)
{
// Remove from hash map first (O(1))
auto mapIt = _elementMap.find(name);
if (mapIt == _elementMap.end())
return false;

_elementMap.erase(mapIt);

// Then remove from vector (O(n) but unavoidable for order preservation)
auto it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name));
if (it != _elements.end())
_elements.erase(it);

return true;
}


inline std::size_t Document::size() const noexcept
{
return _elements.size();
return _elementNames.size();
}


inline const ElementSet& Document::elements() const noexcept
inline const std::vector<std::string>& Document::orderedNames() const noexcept
{
return _elements;
return _elementNames;
}


Expand All @@ -331,7 +306,7 @@ inline void BSONReader::read<Document::Ptr>(Document::Ptr& to)


template<>
inline void BSONWriter::write<Document::Ptr>(Document::Ptr& from)
inline void BSONWriter::write<Document::Ptr>(const Document::Ptr& from)
{
from->write(_writer);
}
Expand Down
21 changes: 9 additions & 12 deletions MongoDB/include/Poco/MongoDB/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// Definition of the Element class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// Copyright (c) 2012-2025, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -64,7 +64,7 @@ class MongoDB_API Element

private:
virtual void read(BinaryReader& reader) = 0;
virtual void write(BinaryWriter& writer) = 0;
virtual void write(BinaryWriter& writer) const = 0;

friend class Document;
std::string _name;
Expand All @@ -80,9 +80,6 @@ inline const std::string& Element::name() const noexcept
}


using ElementSet = std::vector<Element::Ptr>;


template<typename T>
struct ElementTraits
{
Expand Down Expand Up @@ -198,9 +195,9 @@ inline void BSONReader::read<std::string>(std::string& to)


template<>
inline void BSONWriter::write<std::string>(std::string& from)
inline void BSONWriter::write<std::string>(const std::string& from)
{
_writer << (Poco::Int32) (from.length() + 1);
_writer << static_cast<Poco::Int32>(from.length() + 1);
writeCString(from);
}

Expand Down Expand Up @@ -229,7 +226,7 @@ inline void BSONReader::read<bool>(bool& to)


template<>
inline void BSONWriter::write<bool>(bool& from)
inline void BSONWriter::write<bool>(const bool& from)
{
unsigned char b = from ? 0x01 : 0x00;
_writer << b;
Expand Down Expand Up @@ -281,7 +278,7 @@ inline void BSONReader::read<Timestamp>(Timestamp& to)


template<>
inline void BSONWriter::write<Timestamp>(Timestamp& from)
inline void BSONWriter::write<Timestamp>(const Timestamp& from)
{
_writer << (from.epochMicroseconds() / 1000);
}
Expand Down Expand Up @@ -311,7 +308,7 @@ inline void BSONReader::read<NullValue>(NullValue& to)


template<>
inline void BSONWriter::write<NullValue>(NullValue& from)
inline void BSONWriter::write<NullValue>(const NullValue& from)
{
}

Expand Down Expand Up @@ -356,7 +353,7 @@ inline void BSONReader::read<BSONTimestamp>(BSONTimestamp& to)


template<>
inline void BSONWriter::write<BSONTimestamp>(BSONTimestamp& from)
inline void BSONWriter::write<BSONTimestamp>(const BSONTimestamp& from)
{
Poco::Int64 value = from.ts.epochMicroseconds() / 1000;
value <<= 32;
Expand Down Expand Up @@ -420,7 +417,7 @@ class ConcreteElement: public Element
BSONReader(reader).read(_value);
}

void write(BinaryWriter& writer) override
void write(BinaryWriter& writer) const override
{
BSONWriter(writer).write(_value);
}
Expand Down
Loading
Loading