Merge pull request #55419 from evillique/mongo-fix

Fix MongoDB connection issues
This commit is contained in:
Alexey Milovidov 2023-10-10 01:30:04 +02:00 committed by GitHub
commit e204b1d616
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -70,7 +70,7 @@ namespace MongoDB
Document::Ptr queryBuildInfo(Connection & connection) const; Document::Ptr queryBuildInfo(Connection & connection) const;
/// Queries server build info (all wire protocols) /// Queries server build info (all wire protocols)
Document::Ptr queryServerHello(Connection & connection) const; Document::Ptr queryServerHello(Connection & connection, bool old = false) const;
/// Queries hello response from server (all wire protocols) /// Queries hello response from server (all wire protocols)
Int64 count(Connection & connection, const std::string & collectionName) const; Int64 count(Connection & connection, const std::string & collectionName) const;

View File

@ -356,11 +356,19 @@ Document::Ptr Database::queryBuildInfo(Connection& connection) const
} }
Document::Ptr Database::queryServerHello(Connection& connection) const Document::Ptr Database::queryServerHello(Connection& connection, bool old) const
{ {
// hello can be issued on "config" system database // hello can be issued on "config" system database
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createCommand(); Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createCommand();
request->selector().add("hello", 1);
// 'hello' command was previously called 'isMaster'
std::string command_name;
if (old)
command_name = "isMaster";
else
command_name = "hello";
request->selector().add(command_name, 1);
Poco::MongoDB::ResponseMessage response; Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*request, response); connection.sendRequest(*request, response);

View File

@ -370,11 +370,24 @@ namespace
bool isMongoDBWireProtocolOld(Poco::MongoDB::Connection & connection_) bool isMongoDBWireProtocolOld(Poco::MongoDB::Connection & connection_)
{ {
Poco::MongoDB::Database db("config"); Poco::MongoDB::Database db("config");
Poco::MongoDB::Document::Ptr doc = db.queryServerHello(connection_); Poco::MongoDB::Document::Ptr doc = db.queryServerHello(connection_, false);
if (doc->exists("maxWireVersion"))
{
auto wire_version = doc->getInteger("maxWireVersion"); auto wire_version = doc->getInteger("maxWireVersion");
return wire_version < Poco::MongoDB::Database::WireVersion::VER_36; return wire_version < Poco::MongoDB::Database::WireVersion::VER_36;
} }
doc = db.queryServerHello(connection_, true);
if (doc->exists("maxWireVersion"))
{
auto wire_version = doc->getInteger("maxWireVersion");
return wire_version < Poco::MongoDB::Database::WireVersion::VER_36;
}
return true;
}
MongoDBCursor::MongoDBCursor( MongoDBCursor::MongoDBCursor(
const std::string & database, const std::string & database,