Download

Unreal crashes using MongoDB

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

I wonder why the unreal editor wants to free something at that point of the code. If I comment out the else block everything works fine.

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:

921b2232b113c8bde6e4d5045872a9c7bd5bc623.png



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());

    //UE_LOG(LogTemp, Warning, TEXT("Length: %i"), std::distance(Cursor.begin(), Cursor.end()));

    for (auto && Doc : Cursor) {

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

    }
    return;
}


Does the engine allows me to use external objects in the UFUNCTIONS?

I hope you can help me.

Thanks a lot.

Cheers Marcel