HeapError while iterating MongoDB cursor

Hey,

I got an error while or after iterating over a mongocxx::cursor after finding some documents in my database.

I am using Windows 10, Unreal Engine 4.16.1 and mongodb cxx 3.1.1.

The database connection is set up correctly, the find function finds my documents and returns a valid cursor.

It ends up in this Exception:

Exception thrown at 0x00007FFDED56B698 (UE4Editor-Core.dll) in UE4Editor.exe: 0xC0000005: Access violation writing location 0x0000000000000010.

The Engine tries to FREE some memory. I don’t know why.

Here is my method. If I comment out the else block, no error occurs.

void ARMongoDB::BeginPlay()
{
    Super::BeginPlay();

    mongocxx::instance Instance{}; // This should be done only once.
    mongocxx::uri Uri(mongodb://localhost:27017);
    mongocxx::client Client(Uri);
    mongocxx::database Database = Client["UE4DB"];
    mongocxx::collection Collection = Database["UE4Col"];

    // Create the query filter
    auto SearchFilter = bsoncxx::builder::stream::document{} << bsoncxx::builder::stream::finalize;

    // READ DOCUMENT FROM MONGODB
    auto Cursor = Collection.find(SearchFilter.view());

    for (auto && Doc : Cursor) {

        if (Doc.empty())
        {
            UE_LOG(LogTemp, Warning, TEXT("Doc is empty"));
        }
        else
        {
            std::string string = bsoncxx::to_json(Doc);  // <-- Crash
            FString DocJson = string.c_str();
            UE_LOG(LogTemp, Warning, TEXT("Document: %s"), *DocJson);
        }
    }
    return;
}

Am I able to use the external mongo code in the UFUNCTIONS?

Thanks for your help.

Cheers Marcel.