{"id":14956777,"url":"https://github.com/loki-astari/thorsmongo","last_synced_at":"2026-02-17T12:30:55.430Z","repository":{"id":3098153,"uuid":"4123363","full_name":"Loki-Astari/ThorsMongo","owner":"Loki-Astari","description":"C++ MongoDB API and BSON/JSON Serialization library","archived":false,"fork":false,"pushed_at":"2025-02-06T02:58:52.000Z","size":5725,"stargazers_count":318,"open_issues_count":1,"forks_count":73,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-16T00:05:41.074Z","etag":null,"topics":["bson","bson-library","bson-serialization","c-plus-plus","c-plus-plus-20","cxx","database","database-driver","driver","header-only-library","json-serialization","mongo","mongodb","mongodb-driver","networking","nosql"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Loki-Astari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-04-24T10:10:30.000Z","updated_at":"2025-05-15T03:22:04.000Z","dependencies_parsed_at":"2023-12-14T18:51:01.024Z","dependency_job_id":"bdf09063-6bb7-4e84-8719-77b16cf884af","html_url":"https://github.com/Loki-Astari/ThorsMongo","commit_stats":{"total_commits":793,"total_committers":6,"mean_commits":"132.16666666666666","dds":"0.032786885245901676","last_synced_commit":"37f11c9e9426b21136d1337cd4e6c5d0c5b71967"},"previous_names":[],"tags_count":145,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Loki-Astari%2FThorsMongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Loki-Astari%2FThorsMongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Loki-Astari%2FThorsMongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Loki-Astari%2FThorsMongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Loki-Astari","download_url":"https://codeload.github.com/Loki-Astari/ThorsMongo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254442854,"owners_count":22071878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bson","bson-library","bson-serialization","c-plus-plus","c-plus-plus-20","cxx","database","database-driver","driver","header-only-library","json-serialization","mongo","mongodb","mongodb-driver","networking","nosql"],"created_at":"2024-09-24T13:13:30.417Z","updated_at":"2025-05-16T00:06:15.410Z","avatar_url":"https://github.com/Loki-Astari.png","language":"C++","funding_links":["https://ko-fi.com/G2G216KZR3"],"categories":[],"sub_categories":[],"readme":"[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/G2G216KZR3)\n\n# ThorsMongo\n\n[![Brew package](https://img.shields.io/badge/Brew-package-blueviolet)](https://formulae.brew.sh/formula/thors-mongo)\n\n![ThorStream](img/thorsmongo.jpg)\n\nA modern C++20 library to interact with MongoDB.\n\nThis library provides a simple and intuitive library for interacting with a MongoDB.\n\nThere are two main parts:\n\n1. [ThorsSerializer](https://github.com/Loki-Astari/ThorsSerializer) automatically converts C++ objects into BSON (JSON/YAML).\n2. [ThorsMongoAPI](https://github.com/Loki-Astari/ThorsMongoAPI) sends and receives MongoDB wire protocol messages.\n\nThe main goal of this project is to remove the need to write boilerplate code to save/ restore C++ objects into a MongoDB. Using a declarative style an engineer can define the C++ classes and members that need to be serialized into BSON thus allowing them to be inserted into or retrieved directly to/from a MongoDB.\n\n## Example:\n\n```C++\n    #include \"ThorsMongo/ThorsMongo.h\"\n    #include \u003cvector\u003e\n    #include \u003cstring\u003e\n\n    class Address\n    {\n        friend class ThorsAnvil::Serialize::Traits\u003cAddress\u003e;\n        std::string     street;\n        std::string     city;\n        std::string     country;\n        std::string     postCode;\n        public:\n            // Add your API here\n    };\n    using Allergies = std::vector\u003cstd::string\u003e;\n    class Person\n    {\n        friend class ThorsAnvil::Serialize::Traits\u003cPerson\u003e;\n        std::string     name;\n        std::uint32_t   age;\n        Address         address;\n        Allergies       alergies;\n        public:\n            // Add your API here\n    };\n\n    // Make the classes serialize able into BSON.\n    ThorsAnvil_MakeTrait(Address, street, city, country, postCode);\n    ThorsAnvil_MakeTrait(Person, name, age, address, alergies);\n\n    // Define what fields can be used in Search/Update\n    ThorsMongo_CreateFieldAccess(Person, name);             // Search/Update a person by name.\n    ThorsMongo_CreateFieldAccess(Person, age);              // Search/Update a person by age.\n    ThorsMongo_CreateFieldAccess(Person, address, country); // Search/Update a person by country.\n\n    // Define a class that can be used to search for a person by name using 'Eq' (equal)\n    using FindEqName = ThorsMongo_FilterFromAccess(Eq, Person, name);\n    // Define a class that can be used to search for a person by age age using 'Gt' (Greater than)\n    using FindGtAge = ThorsMongo_FilterFromAccess(Gt, Person, age);\n    // Define a class that increments age\n    using IncAge = ThorsMongo_UpdateFromAccess(Inc, Person, age);\n    // Define a class that sets the country.\n    using SetCountry = ThorsMongo_UpdateFromAccess(Set, Person, address, country);\n\n    std::vector\u003cPerson\u003e readDataFromFile()\n    {\n        // Read all the people you want to put in the DB\n        return {};\n    }\n    int main()\n    {\n        using ThorsAnvil::DB::Mongo::ThorsMongo;\n        using ThorsAnvil::DB::Mongo::Query;\n        std::vector\u003cPerson\u003e data = readDataFromFile();  // Write this function to read data from file.\n\n        ThorsMongo  mongo({\"localhost\", 27017}, {\"DbUser\", \"UserPassword\"});\n        mongo[\"DB\"][\"PeopleCollection\"].insert(data);\n        mongo[\"DB\"][\"PeopleCollection\"].remove(Query\u003cFindEqName\u003e{\"John\"});      // Remove all the people named \"John\"\n        auto find = mongo[\"DB\"][\"PeopleCollection\"].find\u003cPerson\u003e(FindGtAge{51});// Find all the people over 51\n        for (auto const\u0026 person: find) {\n            // Now you a person\n        }\n        mongo[\"DB\"][\"PeopleCollection\"].findAndUpdateOne\u003cPerson\u003e(FindEqName{\"Tom\"}, IncAge{2});         // Increment the age of Tom by 2\n        mongo[\"DB\"][\"PeopleCollection\"].findAndUpdateOne\u003cPerson\u003e(FindEqName{\"Sam\"}, SetCountry{\"USA\"}); // Sam now lives in the USA\n    }\n```\n\nBuiling the above application:\n\n```bash\n\u003e export THORS_ROOT=\u003cLocation where ThorsMongo Is Installed\u003e\n\u003e g++ -std=c++20 Example.cpp -I ${THORS_ROOT}/include -L ${THORS_ROOT}/lib -lThorSerialize -lThorsLogging -lThorsMongo -lThorsSocket\n```\n\n# Installing\n\n## Easy: Using Brew\n\nCan be installed via brew on Mac and Linux\n\n    \u003e brew install thors-mongo\n\n* Mac: https://formulae.brew.sh/formula/thors-mongo\n* Linux: https://formulae.brew.sh/formula-linux/thors-mongo\n\n## Building Manually\n\n    \u003e git clone git@github.com:Loki-Astari/ThorsMongo.git\n    \u003e cd ThorsMongo\n    \u003e ./configure\n    \u003e make\n\nNote: The `configure` script will tell you about any missing dependencies and how to install them.\n\n## Building Conan\n\nIf you have conan installed the conan build processes should work.\n\n    \u003e git clone git@github.com:Loki-Astari/ThorsMongo.git\n    \u003e cd ThorsMongo\n    \u003e conan build -s compiler.cppstd=20 conanfile.py\n\n## Header Only\n\nTo install header only version\n\n    \u003e git clone --single-branch --branch header-only https://github.com/Loki-Astari/ThorsMongo.git\n\nSome dependencies you will need to install manually for header only builds.\n\n    Magic Enum: https://github.com/Neargye/magic_enum\n    libYaml     https://github.com/yaml/libyaml\n    libSnappy   https://github.com/google/snappy\n    libZ        https://www.zlib.net/\n\n## Building With Visual Studio\n\nTo build on windows you will need to add the flag: [`/Zc:preprocessor`](https://learn.microsoft.com/en-us/cpp/build/reference/zc-preprocessor?view=msvc-170). These libraries make heavy use of VAR_ARG macros to generate code for you so require conforming pre-processor. See [Macro Expansion of __VA_ARGS__ Bug in Visual Studio?](https://stackoverflow.com/questions/78605945/macro-expansion-of-va-args-bug-in-visual-studio) for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floki-astari%2Fthorsmongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floki-astari%2Fthorsmongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floki-astari%2Fthorsmongo/lists"}