Driver for Godot Engine

There is no server based database driver available with Godot Engine. If MongoDB developers are seeing this topic, will they consider the mongodb library for the Godot Engine?

Hi @Metehan_Ozbek, welcome!

Have you tried connecting to MongoDB using Godot C# scripting ? Looks like you can use NuGet packages in Godot, for example:

  <ItemGroup>
    <PackageReference Include="MongoDB.Driver" Version="2.10.2" />
  </ItemGroup> 

Or alternatively, you could also try to write a GDNative module either in C/C++. For example GDNative C++ , you should be able to write a module with mongocxx driver, see also Tutorial: MongoDB C++ driver.

Regards,
Wan.

1 Like

I’m using gdscript. I don’t have enough skills because I don’t know C ++ :frowning:

Hi Wan,
I have tried what you suggested using C# and the NuGet package. I can successfully access the NuGet package but don’t seem to be able to connect to the database as I get the following error exception when i try to insert a document using:
collection.InsertOne(document);

I can get the same code to work using .NET but fails when run through Godot. Godot is using Mono, is the driver compatible with Mono?

Hi @Chris_Findlay,

The error you listed seems to be related to DnsClient, check that you have connection to the MongoDB server from Godot.

In my test, I could connect from Godot to a locally hosted MongoDB using the following URI: mongodb://127.0.0.1:27107/.

MongoDB .NET/C# driver is not being tested with Mono, although I’ve managed to create a simple test to query a document from MongoDB server using the current driver version 2.10.2. I’ve just added below lines to the csproj file:

      <ItemGroup>
        <PackageReference Include="MongoDB.Driver">
          <Version>2.10.2</Version>
        </PackageReference>
      </ItemGroup>

Tested with Godot Engine 3.2.1 stable mono official, Mono v6.8.0.105 on macOS 10.14.6.

Regards,
Wan.

1 Like

Hi @wan, thanks for your time.

I also added the Nuget package to the csproj file using the same format and has been successful in that part.

I had been trying to connect to a remote cluster I had created but I tried connecting to a local host db after reading your reply. Unfortunately, I’m still not connecting, could you share your code that did connect? Here is the code I am using:

I’m using:
Godot Mono stable 3.2.1
MongoDB.Driver 2.10.2
Windows 10

Regards,
Chris

Hi @Chris_Findlay,

Are you still seeing the same error message relating to DnsClient ?

From a brief look on your code snippet, it looks right. Could you try changing

private String ConnectionString = "mongodb://localhost:27017/";

With

private String ConnectionString = "mongodb://127.0.0.1:27017/"; 

In my test I couldn’t connect locally using localhost either.
Which MongoDB server version are you running ?

Regards,
Wan.

1 Like

Hi @wan, sorry for the delay in getting back. I am currently stuck in isolation in a hotel and have had to re-download everything to my work laptop and start over again.

The good news is I am able to connect and update the collection with the connection string:
private String ConnectionString = "mongodb://127.0.0.1:27017/";
However, when I substitute in my cluster connection string I get the same error as before. I copied and pasted the same string to an almost identical project in VS2019 and confirmed it is valid. I also tried adding an "available anywhere’ entry to the IP whitelist to rule that out.

I am using the same MongoDB driver for both projects.

I’m using:
Godot Mono stable 3.2.1
MongoDB.Driver 2.10.2
Mongo server 4.2.5
Windows 10

Hi @Chris_Findlay,

The DnsClient.DnsDatagramReader.ReadByte error that you are seeing is likely related to either your network setup, or installed DnsClient version. From a quick search, I found DnsClient.NET issues #51, which maybe related to the issue that you’re seeing. Could you try either to install DnsClient v1.3.0, or upgrade MongoDB.Driver to v2.10.3 (which references the DnsClient v1.3.1), and see whether that fixes the issue that you’re seeing.

Regards,
Wan.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.