No i havent changed the code.
Although at first the provided code(connection to database) didnt even ran for Debug as well, error was
No suitable servers found (`serverSelectionTryOnce` set): [Server closed connection. [Server closed connection. calling hello on ac-3***]: genetic server error.
Followed this Fatal error building C++ drivers with VS 2022 under Win10 - are errors OK? - #2 by david_d
Did some tinkering and it worked.
Heres the code that currently works in Debug x64 mode.
#include <mongocxx/client.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <algorithm>
#include <iostream>
#include <vector>
#include <mongocxx/exception/operation_exception.hpp>
using namespace std;
static const mongocxx::uri mongoURI("mongodb+srv://<userName>:<password>@<dbName>.kobcgfr.mongodb.net/?retryWrites=true&w=majority");
// Get all the databases from a given client.
vector<string> getDatabases(mongocxx::client& client)
{
vector<string> cldn = client.list_database_names();
return cldn;
}
int main()
{
// Create an instance.
mongocxx::instance inst{};
mongocxx::options::client client_options;
auto api = mongocxx::options::server_api{ mongocxx::options::server_api::version::k_version_1 };
client_options.server_api_opts(api);
mongocxx::client conn{ mongoURI, client_options };
cout << "password: " << conn.uri().password() << std::endl;
cout << "username: " << conn.uri().username() << std::endl;
cout << "auth_source: " << conn.uri().auth_source() << std::endl;
auto dbs = getDatabases(conn);
for (auto& db : dbs)
{
cout << db << endl;
}
cin.get();
return 0;
}
Heres the call stack :
ntdll.dll!00007ffc38aef3d2()
ntdll.dll!00007ffc38af8192()
ntdll.dll!00007ffc38af847a()
ntdll.dll!00007ffc38afe101()
ntdll.dll!00007ffc38a97482()
ntdll.dll!00007ffc38a147b1()
ucrtbase.dll!00007ffc3663f05b()
[Inline Frame] mongoDBReleaseTesting.exe!std::_Deallocate(void * _Ptr, unsigned __int64 _Bytes) Line 255
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\xmemory(255)
[Inline Frame] mongoDBReleaseTesting.exe!std::allocator<char>::deallocate(char * const _Count, const unsigned __int64) Line 829
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\xmemory(829)
[Inline Frame] mongoDBReleaseTesting.exe!std::string::_Tidy_deallocate() Line 5019
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\xstring(5019)
[Inline Frame] mongoDBReleaseTesting.exe!std::string::{dtor}() Line 3270
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\xstring(3270)
mongoDBReleaseTesting.exe!main() Line 49
at D:\WorkSpace\VisualStudio2017\Projects\c++ playground\mongoDBReleaseTesting\mongoDBReleaseTesting.cpp(49)
[External Code]