├── addons └── MongoDB │ ├── mongoDB-icon.png │ ├── mongodb-bridge-icon.png │ ├── MongoDocument │ ├── _MongoDocument.cs │ └── MongoDocument.tscn │ ├── plugin.cfg │ ├── MongoClient │ ├── MongoClient.tscn │ └── _MongoClient.cs │ ├── MongoDatabase │ ├── MongoDatabase.tscn │ └── _MongoDatabase.cs │ ├── MongoCollection │ ├── MongoCollection.tscn │ └── _MongoCollection.cs │ ├── mongoDB-icon.png.import │ ├── mongodb-bridge.gd │ ├── MongoAPI.cs │ └── Utils │ └── Converters.cs ├── .gitignore ├── LICENSE └── README.md /addons/MongoDB/mongoDB-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fenix-hub/godot-engine.MongoDB-bridge/HEAD/addons/MongoDB/mongoDB-icon.png -------------------------------------------------------------------------------- /addons/MongoDB/mongodb-bridge-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fenix-hub/godot-engine.MongoDB-bridge/HEAD/addons/MongoDB/mongodb-bridge-icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Godot-specific ignores 3 | .import/ 4 | export.cfg 5 | export_presets.cfg 6 | 7 | # Mono-specific ignores 8 | .mono/ 9 | data_*/ 10 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoDocument/_MongoDocument.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using System; 3 | 4 | public class _MongoDocument : Node 5 | { 6 | 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /addons/MongoDB/plugin.cfg: -------------------------------------------------------------------------------- 1 | [plugin] 2 | 3 | name="MongoDB Bridge" 4 | description="A MonoDB bridge written in C# for Godot Engine mono projects" 5 | author="Nicolo (fenix) Santilio" 6 | version="1.0.0" 7 | script="mongodb-bridge.gd" 8 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoClient/MongoClient.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=2] 2 | 3 | [ext_resource path="res://addons/MongoDB/MongoClient/_MongoClient.cs" type="Script" id=1] 4 | 5 | [node name="MongoClient" type="Node"] 6 | script = ExtResource( 1 ) 7 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoDatabase/MongoDatabase.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=2] 2 | 3 | [ext_resource path="res://addons/MongoDB/MongoDatabase/_MongoDatabase.cs" type="Script" id=1] 4 | 5 | [node name="MongoDatabase" type="Node"] 6 | script = ExtResource( 1 ) 7 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoDocument/MongoDocument.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=2] 2 | 3 | [ext_resource path="res://addons/MongoDB/MongoDocument/_MongoDocument.cs" type="Script" id=1] 4 | 5 | [node name="MongoDocument" type="Node"] 6 | script = ExtResource( 1 ) 7 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoCollection/MongoCollection.tscn: -------------------------------------------------------------------------------- 1 | [gd_scene load_steps=2 format=2] 2 | 3 | [ext_resource path="res://addons/MongoDB/MongoCollection/_MongoCollection.cs" type="Script" id=1] 4 | 5 | [node name="MongoCollection" type="Node"] 6 | script = ExtResource( 1 ) 7 | -------------------------------------------------------------------------------- /addons/MongoDB/mongoDB-icon.png.import: -------------------------------------------------------------------------------- 1 | [remap] 2 | 3 | importer="texture" 4 | type="StreamTexture" 5 | path="res://.import/mongoDB-icon.png-f4dd11bef468ad5decdab4e5ea70b270.stex" 6 | metadata={ 7 | "vram_texture": false 8 | } 9 | 10 | [deps] 11 | 12 | source_file="res://addons/MongoDB/mongoDB-icon.png" 13 | dest_files=[ "res://.import/mongoDB-icon.png-f4dd11bef468ad5decdab4e5ea70b270.stex" ] 14 | 15 | [params] 16 | 17 | compress/mode=0 18 | compress/lossy_quality=0.7 19 | compress/hdr_mode=0 20 | compress/bptc_ldr=0 21 | compress/normal_map=0 22 | flags/repeat=0 23 | flags/filter=true 24 | flags/mipmaps=false 25 | flags/anisotropic=false 26 | flags/srgb=2 27 | process/fix_alpha_border=true 28 | process/premult_alpha=false 29 | process/HDR_as_SRGB=false 30 | process/invert_color=false 31 | stream=false 32 | size_limit=0 33 | detect_3d=true 34 | svg/scale=1.0 35 | -------------------------------------------------------------------------------- /addons/MongoDB/mongodb-bridge.gd: -------------------------------------------------------------------------------- 1 | tool 2 | extends EditorPlugin 3 | var _MongoAPI : String = ("res://addons/MongoDB/MongoAPI.cs") 4 | var _MongoClient : String = ("res://addons/MongoDB/MongoClient/_MongoClient.cs") 5 | var _MongoDatabase : String = ("res://addons/MongoDB/MongoDatabase/_MongoDatabase.cs") 6 | var _MongoCollection : String = ("res://addons/MongoDB/MongoCollection/_MongoCollection.cs") 7 | 8 | 9 | func _enter_tree(): 10 | add_autoload_singleton("MongoAPI",_MongoAPI) 11 | add_autoload_singleton("MongoClient",_MongoClient) 12 | add_autoload_singleton("MongoDatabase",_MongoDatabase) 13 | add_autoload_singleton("MongoCollection",_MongoCollection) 14 | 15 | func _exit_tree(): 16 | remove_autoload_singleton("MongoAPI") 17 | remove_autoload_singleton("MongoClient") 18 | remove_autoload_singleton("MongoDatabase") 19 | remove_autoload_singleton("MongoCollection") 20 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoAPI.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using Godot.Collections; 3 | using System; 4 | using System.Collections.Generic; 5 | using MongoDB.Bson; 6 | using MongoDB.Driver; 7 | using MongoDB.Driver.Core; 8 | 9 | public class MongoAPI : Node 10 | { 11 | [Export] 12 | private String host = "mongodb://127.0.0.1:27017"; 13 | private String addonPath = "res://addons/MongoDB/"; 14 | public _MongoClient Connect(String hostIp){ 15 | return this.Connect(hostIp, true); 16 | } 17 | public _MongoClient Connect(String hostIp, bool checkSslCertificate) 18 | { 19 | host = hostIp; 20 | var MongoClientScene = (PackedScene) ResourceLoader.Load(addonPath+"MongoClient/MongoClient.tscn"); 21 | var ClientScene = MongoClientScene.Instance() as _MongoClient; 22 | AddChild(ClientScene); 23 | ClientScene.LoadClient(new MongoClient(host), addonPath, checkSslCertificate); 24 | ClientScene.Name = host; 25 | return ClientScene; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nicolò Santilio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /addons/MongoDB/Utils/Converters.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using Godot.Collections; 3 | using System; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | using MongoDB.Bson; 7 | using MongoDB.Bson.IO; 8 | using MongoDB.Driver; 9 | using MongoDB.Driver.Core; 10 | 11 | public static class Converters 12 | { 13 | 14 | public static String ConvertBsonDocumentToString(BsonDocument BsonDocument) 15 | { 16 | return BsonDocument.ToString(); 17 | } 18 | 19 | public static Dictionary ConvertBsonDocumentToDictionary(BsonDocument BsonDocument) 20 | { 21 | var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }; 22 | var jsonStringDocument = BsonDocument.ToJson(jsonWriterSettings); 23 | var jsonDocument = JSON.Parse(jsonStringDocument).Result; 24 | return (Dictionary) jsonDocument; 25 | } 26 | 27 | public static BsonDocument ConvertDictionaryToBsonDocument(Dictionary dictionary) 28 | { 29 | var documentString = JSON.Print(dictionary); 30 | var BSONdocument = BsonDocument.Parse(documentString); 31 | return BSONdocument; 32 | } 33 | 34 | public static Godot.Collections.Array ConvertBsonListToArray(List bsonList) 35 | { 36 | var array = new Godot.Collections.Array(); 37 | foreach (BsonDocument bson in bsonList) 38 | { 39 | array.Add(ConvertBsonDocumentToString(bson)); 40 | } 41 | return array; 42 | } 43 | 44 | public static Godot.Collections.Array ConvertBsonListToJsonList(List bsonList) 45 | { 46 | var array = new Godot.Collections.Array(); 47 | foreach (BsonDocument bson in bsonList) 48 | array.Add(ConvertBsonDocumentToDictionary(bson)); 49 | return array; 50 | } 51 | 52 | public static Godot.Collections.Array ConvertStringListToArray(List stringList) 53 | { 54 | var array = new Godot.Collections.Array(); 55 | foreach (String _string in stringList) 56 | { 57 | array.Add(_string); 58 | } 59 | return array; 60 | } 61 | 62 | 63 | } -------------------------------------------------------------------------------- /addons/MongoDB/MongoClient/_MongoClient.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using Godot.Collections; 3 | using System; 4 | using System.Security.Authentication; 5 | using System.Collections.Generic; 6 | using MongoDB.Bson; 7 | using MongoDB.Driver; 8 | using MongoDB.Driver.Core; 9 | 10 | public class _MongoClient : Node 11 | { 12 | 13 | private String addonPath; 14 | private MongoClient client; 15 | 16 | public void LoadClient(MongoClient mongoClient, String path, bool checkSslCertificate) 17 | { 18 | client = mongoClient; 19 | addonPath = path; 20 | 21 | if (!checkSslCertificate){ 22 | var settings = client.Settings.Clone(); 23 | settings.SslSettings = new SslSettings() { 24 | CheckCertificateRevocation = true, 25 | ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true 26 | }; 27 | 28 | client = new MongoClient(settings); 29 | } 30 | 31 | } 32 | 33 | public Godot.Collections.Array GetDatabaseList() 34 | { 35 | var databaseList = client.ListDatabases().ToList(); 36 | var databaseArray = Converters.ConvertBsonListToJsonList(databaseList); 37 | return databaseArray; 38 | } 39 | 40 | public Godot.Collections.Array GetDatabaseNameList() 41 | { 42 | var databaseNameList = client.ListDatabaseNames().ToList(); 43 | var databaseNameArray = Converters.ConvertStringListToArray(databaseNameList); 44 | return databaseNameArray; 45 | } 46 | 47 | public _MongoDatabase GetDatabase(String databaseName) 48 | { 49 | var database = client.GetDatabase(databaseName); 50 | _MongoDatabase DatabaseScene = null; 51 | if (!HasNode(databaseName)) 52 | { 53 | var MongoDatabaseScene = (PackedScene) ResourceLoader.Load(addonPath+"MongoDatabase/MongoDatabase.tscn"); 54 | DatabaseScene = MongoDatabaseScene.Instance() as _MongoDatabase; 55 | AddChild(DatabaseScene); 56 | DatabaseScene.LoadDatabase(database, addonPath); 57 | DatabaseScene.Name = databaseName; 58 | } 59 | else { 60 | DatabaseScene = (_MongoDatabase)GetNode(databaseName); 61 | } 62 | 63 | return DatabaseScene; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoDatabase/_MongoDatabase.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using Godot.Collections; 3 | using System; 4 | using System.Collections.Generic; 5 | using MongoDB.Bson; 6 | using MongoDB.Driver; 7 | using MongoDB.Driver.Core; 8 | 9 | public class _MongoDatabase : Node 10 | { 11 | 12 | private IMongoDatabase database; 13 | private String addonPath; 14 | 15 | public void LoadDatabase(IMongoDatabase db, String path) 16 | { 17 | database = db; 18 | addonPath = path; 19 | } 20 | 21 | public Godot.Collections.Array GetCollectionsList() 22 | { 23 | return Converters.ConvertBsonListToArray(database.ListCollections().ToList()); 24 | } 25 | public Godot.Collections.Array GetCollectionsNameList() 26 | { 27 | return Converters.ConvertStringListToArray(database.ListCollectionNames().ToList()); 28 | } 29 | 30 | public _MongoCollection GetCollection(String collectionName) 31 | { 32 | var collection = database.GetCollection(collectionName); 33 | _MongoCollection CollectionScene = null; 34 | if (!HasNode(collectionName)) { 35 | var MongoCollectionScene = (PackedScene) ResourceLoader.Load(addonPath+"MongoCollection/MongoCollection.tscn"); 36 | CollectionScene = (_MongoCollection)MongoCollectionScene.Instance(); 37 | AddChild(CollectionScene); 38 | CollectionScene.LoadCollection(collection, addonPath); 39 | CollectionScene.Name = collectionName; 40 | } 41 | else { 42 | CollectionScene = (_MongoCollection) GetNode(collectionName); 43 | } 44 | return CollectionScene; 45 | } 46 | 47 | public _MongoCollection CreateCollection(String collectionName) 48 | { 49 | try 50 | { 51 | database.CreateCollection(collectionName); 52 | } 53 | catch (System.Exception) 54 | { 55 | GD.PrintErr("[MongoDB Bridge] >> A collection named '"+collectionName+"' already exists in the current database. The existing one is returned"); 56 | } 57 | return GetCollection(collectionName); 58 | } 59 | 60 | public void DropCollection(String collectionName) 61 | { 62 | database.DropCollection(collectionName); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /addons/MongoDB/MongoCollection/_MongoCollection.cs: -------------------------------------------------------------------------------- 1 | using Godot; 2 | using Godot.Collections; 3 | using System; 4 | using System.Linq; 5 | using System.Collections.Generic; 6 | using MongoDB.Bson; 7 | using MongoDB.Driver; 8 | using MongoDB.Driver.Core; 9 | using MongoDB.Bson.IO; 10 | 11 | public class _MongoCollection : Node 12 | { 13 | private IMongoCollection BsonCollection; 14 | private Dictionary JsonCollection; 15 | private String addonPath; 16 | 17 | // ---- 18 | 19 | public Godot.Collections.Array documents; 20 | 21 | // --- PRIVATE FUNCTIONS : DON'T USE THEM UNLESS DIRECTLY USING C# 22 | 23 | public void LoadCollection(IMongoCollection collection, String path) 24 | { 25 | BsonCollection = collection; 26 | addonPath = path; 27 | AutoRetrieveDocument(); 28 | } 29 | 30 | private Godot.Collections.Array RetrieveDocuments() 31 | { 32 | var filterDB = Builders.Filter.Empty; 33 | var findDocumentDB = BsonCollection.Find(filterDB).ToList(); 34 | Godot.Collections.Array documents = Converters.ConvertBsonListToJsonList(findDocumentDB); 35 | return documents; 36 | } 37 | 38 | private void AutoRetrieveDocument() 39 | { 40 | documents = RetrieveDocuments(); 41 | } 42 | 43 | // -------------------------------------------------- 44 | 45 | public Godot.Collections.Array GetDocuments() 46 | { 47 | return documents; 48 | } 49 | 50 | public void InsertDocument(Godot.Collections.Dictionary document, String id) 51 | { 52 | if (id!=null && id!="" && id!=" ") 53 | { 54 | document.Add("_id", id); 55 | } 56 | 57 | BsonCollection.InsertOne(Converters.ConvertDictionaryToBsonDocument(document)); 58 | AutoRetrieveDocument(); 59 | } 60 | 61 | public void InsertManyDocuments(Godot.Collections.Array documentsList) 62 | { 63 | var documents = Enumerable.Range(0, documentsList.Count).Select(i => Converters.ConvertDictionaryToBsonDocument(documentsList[i])); 64 | BsonCollection.InsertMany(documents); 65 | AutoRetrieveDocument(); 66 | } 67 | 68 | public int CountDocuments() 69 | { 70 | return (int) BsonCollection.CountDocuments(new BsonDocument()); 71 | } 72 | 73 | public Dictionary GetDocument(String id) 74 | { 75 | try 76 | { 77 | FilterDefinition filter; 78 | 79 | 80 | try 81 | { 82 | filter = Builders.Filter.Eq("_id", id); 83 | } 84 | catch (System.Exception) 85 | { 86 | } 87 | finally 88 | { 89 | filter = Builders.Filter.Eq("_id", ObjectId.Parse(id)); 90 | } 91 | 92 | try 93 | { 94 | var findDocument = BsonCollection.Find(filter).First(); 95 | return Converters.ConvertBsonDocumentToDictionary(findDocument); 96 | 97 | } 98 | catch(System.Exception) 99 | { 100 | } 101 | finally 102 | { 103 | } 104 | 105 | } 106 | catch 107 | { 108 | 109 | } 110 | finally 111 | { 112 | 113 | } 114 | var output = new Godot.Collections.Dictionary(); 115 | return output; 116 | } 117 | 118 | public Godot.Collections.Array FindDocumentsBy(String key, String value) 119 | { 120 | var filter = Builders.Filter.Eq(key, value); 121 | var findDocument = BsonCollection.Find(filter).ToList(); 122 | return Converters.ConvertBsonListToJsonList(findDocument); 123 | } 124 | 125 | public void UpdateDocumentBy(String key, String oldValue, String newValue) 126 | { 127 | var filter = Builders.Filter.Eq(key, oldValue); 128 | var update = Builders.Update.Set(key, newValue); 129 | 130 | BsonCollection.UpdateOne(filter, update); 131 | AutoRetrieveDocument(); 132 | } 133 | public void UpdateDocumentsBy(String key, String oldValue, String newValue) 134 | { 135 | var filter = Builders.Filter.Eq(key, oldValue); 136 | var update = Builders.Update.Set(key, newValue); 137 | BsonCollection.UpdateMany(filter, update); 138 | AutoRetrieveDocument(); 139 | } 140 | 141 | public void ReplaceOne(String key, String value, Dictionary replacement) 142 | { 143 | var filter = Builders.Filter.Eq(key, value); 144 | BsonCollection.ReplaceOne(filter, Converters.ConvertDictionaryToBsonDocument(replacement)); 145 | AutoRetrieveDocument(); 146 | } 147 | 148 | public void ReplaceOneByID(String id, Dictionary replacement) 149 | { 150 | var filter = Builders.Filter.Eq("_id", ObjectId.Parse(id)); 151 | BsonCollection.ReplaceOne(filter, Converters.ConvertDictionaryToBsonDocument(replacement)); 152 | AutoRetrieveDocument(); 153 | } 154 | 155 | public void DeleteDocumentBy(String key, String value) 156 | { 157 | var filter = Builders.Filter.Eq(key, value); 158 | BsonCollection.DeleteOne(filter); 159 | AutoRetrieveDocument(); 160 | } 161 | 162 | public void DeleteDocumentByID(String id) 163 | { 164 | var filter = Builders.Filter.Eq("_id", ObjectId.Parse(id)); 165 | BsonCollection.DeleteOne(filter); 166 | AutoRetrieveDocument(); 167 | } 168 | 169 | public void DeleteDocumentsBy(String key, String value) 170 | { 171 | var filter = Builders.Filter.Eq(key, value); 172 | BsonCollection.DeleteMany(filter); 173 | AutoRetrieveDocument(); 174 | } 175 | 176 | 177 | } 178 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | discord 4 | 5 |

6 | 7 | 8 | 9 | # Godot Engine - MongoDB Bridge 10 | **A MongoDB bridge written in C# for Godot Engine mono projects.** 11 | - [How does it work?](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#how-does-it-work) 12 | - [What is MongoDB?](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#what-is-mongodb) 13 | - [What is NuGet and why do I need it?](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#what-is-nuget-and-why-do-i-need-it) 14 | - [Why can I only use this plugin with the Mono version?](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#why-can-i-only-use-this-plugin-with-the-mono-version?) 15 | - [Table of Features](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#table-of-features) 16 | - [Some examples](https://github.com/fenix-hub/godot-engine.MongoDB-bridge#some-examples) 17 | 18 | ## How does it work? 19 | *MongoDB Bridge* is a collection of scripts written in C# which interface MongoDB APIs to work with a MongoDB database even with GDScript. 20 | To make this plugin work: 21 | 1. [install MongoDB](https://www.mongodb.com/try/download/community) on your local machine (or remote machine), 22 | 2. [install NuGet](https://www.nuget.org/downloads), 23 | 3. install this repository as a common Godot Engine addon, using the AssetLibrary or just cloning this repo in your **mono** project, 24 | 4. edit your `.csproj`, adding after the line including `` the following: 25 | ``` 26 | 27 | 2.10.4 28 | 29 | 30 | 2.10.4 31 | 32 | 33 | 2.10.4 34 | 35 | ``` 36 | 5. use the command `nuget restore` via a command line at your choice 37 |
38 | 39 | 40 | ## What is MongoDB? 41 | *MongoDB* is a document database, which means it stores data in JSON-like documents called **BSON**. 42 | [BSON](https://docs.mongodb.com/manual/reference/bson-types/) is a binary serialization format used to store documents and make remote procedure calls in MongoDB. 43 | The BSON specification is located at [bsonspec.org](bsonspec.org). 44 | > Read more aboute MongoDB [here](https://docs.mongodb.com/manual/introduction/). 45 |
46 | 47 | 48 | 49 | ## What is NuGet and why do I need it? 50 | *NuGet* is the package manager for .NET. The NuGet client tools provide the ability to produce and consume packages. The NuGet Gallery is the central package repository used by all package authors and consumers. 51 | NuGet is required to correctly download and implement dipendencies in C# projects just referencing them in the `.csproj` file with a ``. 52 |
53 | 54 | ## :grey_question: Why can I only use this plugin with the Mono version? 55 | Even though Godot Engine currently supports [Cross-Language Scripting](https://docs.godotengine.org/it/stable/getting_started/scripting/cross_language_scripting.html) without the need of a .mono project, .cs files in this addon intensively rely on `MongoDB` Packages. 56 | In order to compile these packages and build the project, a mono project is required. Otherwise, a C++ module implementing MongoDB APIs should be compiled, but that's not the case (even though it is something I'm working on). 57 | But **note**, this doesn't mean you need to write your whole project in C# if you want to use MongoDB APIs: this is why I made this bridge, indeed. 58 | *MongoDB Bridge* lets you write your whole project in GDScript without caring too much about C# stuff, and still access to all main functionalities you would have directly working with [MongoDB C# Drivers](https://docs.mongodb.com/drivers/). 59 |
60 | 61 | 62 | 63 | ## Table of Features 64 | | Class | Description | 65 | | ------------- | ------------- | 66 | |`MongoAPI`|Instance of the API to initialize the Bridge and connect to a MongoDB server| 67 | |`MongoClient`|Instance of a client connected to a specific server, containing a set of databases| 68 | |`MongoDatabase`|Instance of a single database containing multiple collections of documents| 69 | |`MongoCollection`|Instance of a collection of BSON/JSON documents| 70 |
71 | 72 | **MongoAPI** 73 | | Method | Type | Description | 74 | | ------------- | ------------- | ------------- | 75 | |`Connect(hostIp : String)`|`MongoClient`|Connect to a server in order to retrieve a client. You can get the default `hostIp` with `MongoAPI.host`, which is `mongodb://127.0.0.1:27017`| 76 | |`Connect(hostIp : String, checkSslCertificate : Bool)`|`MongoClient`|Connect to a server in order to retrieve a client. If `checkSslCertificate` is set to `false` mongodb will connect without verifying SSL certificates| 77 |
78 | 79 | **MongoClient** 80 | | Method | Type | Description | 81 | | ------------- | ------------- | ------------- | 82 | |`GetDatabaseList()`|`Array`|Return an `Array` of different `Dictionary` containing all databases belonging to the `MongoClient` connected| 83 | |`GetDatabaseNameList()`|`Array`|Return an `Array` of different `String` containing all databases' names belonging to the `MongoClient` connected| 84 | |`GetDatabase(database_name : String)`|`MongoDatabase`|Return a specific `MongoDatabase` by its name| 85 |
86 | 87 | **MongoDatabase** 88 | | Method | Type | Description | 89 | | ------------- | ------------- | ------------- | 90 | |`GetCollectionsList()`|`Array`|Return an `Array` of different `String` representing all collections contained in the specified database| 91 | |`GetCollectionsNameList()`|`Array`|Return an `Array` of different `String` containing all collections' names contained in the specified database| 92 | |`GetCollection(collection_name : String)`|`MongoCollection`|Return a specific `MongoCollection` inside the database by its name| 93 | |`CreateCollection(collection_name : String)`|`MongoCollection`|Create a new `MongoCollection` and return it| 94 | |`DropCollection(collection_name : String)`|`void`|Drop a specific `MongoCollection`| 95 |
96 | 97 | **MongoCollection** 98 | | Method | Type | Description | 99 | | ------------- | ------------- | ------------- | 100 | |`GetDocuments()`|`Array`|Return an `Array` of different `Dictionary` representing a single document. The `Dictionary` is a serialization of a `BSON` document parsed to a GDScript `JSON`| 101 | |`InsertDocument(document : Dictionary, _id : String)`|`void`|Insert a `BSON` document in the collection, parsed by a GDScript `Dictionary`. **note:** the \_id is not mandatory, but it always needs to be `null`,`""` or `" "` if you don't want to define an \_id| 102 | |`InsertManyDocuments(document_list : Array)`|`void`|Insert multiple `BSON` documents in the collection, parsed by an `Array` of GDScript different `Dictionary`| 103 | |`CountDocuments()`|`int`|Count the number of `Documents` in the `MongoCollection`| 104 | |`GetDocument(_id : String)`|`Dictionary`|Return a specific document as a `Dictionary`| 105 | |`FindDocumentsBy(key : String, value : String)`|`Array`|Return an `Array` of different `Dictionary` representing the documents that respect the query with the specified `key` and `value`| 106 | |`UpdateDocumentBy(key : String, oldValue : String, newValue : String)`|`void`|Update the first document found with a `key:value` query, replacing the `oldValue` with the `newValue`| 107 | |`UpdateDocumentsBy(key : String, oldValue : String, newValue : String)`|`void`|Update all the documents found with a `key:value` query, replacing the `oldValue` with the `newValue` in each one of them| 108 | |`DeleteDocumentBy(key : String, value : String)`|`void`|Delete the first document found with a `key:value` query| 109 | |`DeleteDocumentByID(String id)`|`void`|Delete the first document found with an `_id` query| 110 | |`DeleteDocumentsBy(key : String, value : String)`|`void`|Delete all the documents found with a `key:value` query| 111 | |`ReplaceOne(key : String, value : String, replacement_document : Dictionary)`|`void`| Replace document found with a `key:value` query| 112 | |`ReplaceOneByID(id : String, replacement_document : Dictionary)`|`void`| Replace document found with an `_id` query| 113 |
114 | 115 | ## Some examples 116 | ```gdscript 117 | var client : MongoClient = MongoAPI.Connect(MongoAPI.host); 118 | var database_list : Array = client.GetDatabaseList(); 119 | var database_namelist : Array = client.GetDatabaseNameList(); 120 | var database : MongoDatabase = client.GetDatabase(database_namelist[2]); 121 | var collections_namelist : Array = database.GetCollectionsNameList(); 122 | var collection : MongoCollection = database.GetCollection(collections_namelist[0]); 123 | var documents_list : Array = collection.GetDocuments(); 124 | var document : Dictionary = documents_list[0]; 125 | print(document); 126 | print(document.name); 127 | ``` 128 | --------------------------------------------------------------------------------