├── DnsClient.dll ├── Model_Upload.cs ├── Model_User.cs ├── MongoDB.Bson.dll ├── MongoDB.Driver.Core.dll ├── MongoDB.Driver.dll ├── README.md └── System.Buffers.dll /DnsClient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Julian23517/Unity-mongo-csharp-driver-dlls/0ef06a3788112060da03fe32d7defc5cf9550967/DnsClient.dll -------------------------------------------------------------------------------- /Model_Upload.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Driver; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class Model_Upload : MonoBehaviour 6 | { 7 | private const string MONGO_URI = "mongodb://127.0.0.1:27017"; 8 | private const string DATABASE_NAME = "testDatabase"; 9 | private MongoClient client; 10 | private IMongoDatabase db; 11 | 12 | void Start() 13 | { 14 | client = new MongoClient(MONGO_URI); 15 | db = client.GetDatabase(DATABASE_NAME); 16 | IMongoCollection userCollection = db.GetCollection("collectionName"); 17 | Model_User e = new Model_User(); 18 | e.name = "hope"; 19 | userCollection.InsertOne(e); 20 | List userModelList = userCollection.Find(user => true).ToList(); 21 | Model_User[] userAsap= userModelList.ToArray(); 22 | foreach(Model_User asap in userAsap) 23 | { 24 | print(asap.name); 25 | } 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Model_User.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using MongoDB.Driver; 5 | using MongoDB.Bson; 6 | // Model_User Sample 7 | public class Model_User 8 | { 9 | public ObjectId _id { set; get; } 10 | public string name { set; get; } 11 | 12 | public int ActiveConnection { set; get; } 13 | public string Username { private set; get; } 14 | public string Email { private set; get; } 15 | public string ShaPassword { private set; get; } 16 | 17 | //Possible Methods ... 18 | } 19 | -------------------------------------------------------------------------------- /MongoDB.Bson.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Julian23517/Unity-mongo-csharp-driver-dlls/0ef06a3788112060da03fe32d7defc5cf9550967/MongoDB.Bson.dll -------------------------------------------------------------------------------- /MongoDB.Driver.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Julian23517/Unity-mongo-csharp-driver-dlls/0ef06a3788112060da03fe32d7defc5cf9550967/MongoDB.Driver.Core.dll -------------------------------------------------------------------------------- /MongoDB.Driver.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Julian23517/Unity-mongo-csharp-driver-dlls/0ef06a3788112060da03fe32d7defc5cf9550967/MongoDB.Driver.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity-mongo-csharp-driver-dlls 2 | 3 | These are the dlls that you have to include in a Plugins folder inside of your Unity Project. 4 | 5 | Then you can access your Database like this (replace username, password, DATABASE_NAME and 127.0.0.1 (127.0.0.1 only, if you host your database elsewhere)): 6 | 7 | ```script 8 | using MongoDB.Driver; 9 | 10 | private const string MONGO_URI = "mongodb://username:password@127.0.0.1:27017"; 11 | private const string DATABASE_NAME = "testDatabase"; 12 | private MongoClient client; 13 | private IMongoDatabase db; 14 | 15 | client = new MongoClient(MONGO_URI); 16 | db = client.GetDatabase(DATABASE_NAME); 17 | 18 | ``` 19 | ```script 20 | ``` 21 | # Reference Collection: 22 | Replace Model_User with your Model Class 23 | Replace collectionName with the name of the collection you want to reference 24 | make sure that the Model Class has public getter on all Properties and a public ObjectId _id with public getter and setter 25 | ```script 26 | private readonly IMongoCollection userCollection = db.GetCollection("collectionName"); 27 | ``` 28 | 29 | ```script 30 | // Model_User Sample 31 | public class Model_User { 32 | public ObjectId _id { set; get; } 33 | 34 | public int ActiveConnection { set; get; } 35 | public string Username { private set; get; } 36 | public string Email { private set; get; } 37 | public string ShaPassword { private set; get; } 38 | 39 | //Possible Methods ... 40 | } 41 | ``` 42 | 43 | # Get All Models from Collection 44 | Replace Model_User with your Model Class that represents a document in the Collection 45 | Replace userCollection with the referenced collection 46 | You Could replace "true" with a condition that matches the specific documents you want to get 47 | ```script 48 | List userModelList = userCollection.Find(user => true).ToList(); 49 | ``` 50 | 51 | # Get a Single Model from Collection (or null if no match was found) 52 | Replace Model_User with your Model Class that represents a document in the collection 53 | Replace userCollection with the referenced collection 54 | Replace "user._id.Equals(id)" with whatever your condition should be that matches the document 55 | ```script 56 | Model_User modelUser = userCollection.Find(user => user._id.Equals(id)).SingleOrDefault(); 57 | ``` 58 | 59 | # Insert One Document to Collection (Post) 60 | Replace userCollection with the referenced collection 61 | Replace newModelUser with the Model you want to insert into the collection 62 | ```script 63 | userCollection.InsertOne(newModelUser); 64 | ``` 65 | 66 | # Replace One Document in Collection (Update) 67 | Replace userCollection with the referenced collection 68 | Replace newModelUser with the new version of your model you want to update 69 | ```script 70 | userCollection.FindOneAndReplace(user => user._id == newModelUser._id, newModelUser); 71 | ``` 72 | 73 | # Update Many Documents in Collection 74 | Replace userCollection with the referenced collection 75 | Replace "user.ActiveConnection != 0" with the condition that should match the documents you want to update 76 | Replace "user => user.ActiveConnection, 0" with the Attribute you want to change and the value you want to set to that Attribute 77 | ```script 78 | // on all users that have a ActiveConnection different from 0, set ActiveConnection to 0 79 | userCollection.UpdateMany(user => user.ActiveConnection != 0, Builders.Update.Set(user => user.ActiveConnection, 0)); 80 | ``` 81 | -------------------------------------------------------------------------------- /System.Buffers.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Julian23517/Unity-mongo-csharp-driver-dlls/0ef06a3788112060da03fe32d7defc5cf9550967/System.Buffers.dll --------------------------------------------------------------------------------