mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #55419 from evillique/mongo-fix
Fix MongoDB connection issues
This commit is contained in:
commit
e204b1d616
@ -70,7 +70,7 @@ namespace MongoDB
|
||||
Document::Ptr queryBuildInfo(Connection & connection) const;
|
||||
/// 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)
|
||||
|
||||
Int64 count(Connection & connection, const std::string & collectionName) const;
|
||||
|
@ -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
|
||||
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;
|
||||
connection.sendRequest(*request, response);
|
||||
|
@ -370,9 +370,22 @@ namespace
|
||||
bool isMongoDBWireProtocolOld(Poco::MongoDB::Connection & connection_)
|
||||
{
|
||||
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");
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user