d0p3t
8
I just connected to MongoDB and inserted a simple document without any issues using the official mongo-csharp-driver (link) through NuGet. I got no dependency issues when starting the server.
Server Console
MongoDB Shell
Code:
using System;
using System.Threading.Tasks;
using CitizenFX.Core;
using MongoDB.Bson;
using MongoDB.Driver;
namespace FivemTest
{
public class User {
public ObjectId Id { get; set; }
public string Name { get; set; }
}
public class MyClass : BaseScript
{
MongoClient client;
IMongoDatabase database;
IMongoCollection<FivemTest.User> collection;
bool firstTick = true;
public MyClass()
{
client = new MongoClient("mongodb://localhost:27017");
database = client.GetDatabase("foo");
collection = database.GetCollection<User>("bar");
Tick += OnTick;
}
private async Task OnTick(){
if (firstTick)
{
await collection.InsertOneAsync(new User { Name = "d0p3t" });
var list = await collection.Find(x => x.Name == "d0p3t")
.ToListAsync();
foreach (var person in list)
{
Debug.WriteLine(person.Name);
}
firstTick = false;
Debug.WriteLine("DONE");
}
}
}
}
So I don’t know what driver you guys try to use, but this works.
I’m on Linux using the latest artifact.