{"id":28717166,"url":"https://github.com/quarkpunk/mongoose","last_synced_at":"2026-05-04T13:33:51.988Z","repository":{"id":298941125,"uuid":"999007749","full_name":"quarkpunk/mongoose","owner":"quarkpunk","description":"Simple and efficient C++ client for MongoDB, inspired by the Mongoose JavaScript library","archived":false,"fork":false,"pushed_at":"2025-06-13T17:49:47.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-13T18:43:51.504Z","etag":null,"topics":["cmake","cpp","json","mongocxx","mongodb","mongoose"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quarkpunk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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":"2025-06-09T15:40:20.000Z","updated_at":"2025-06-13T17:49:50.000Z","dependencies_parsed_at":"2025-06-13T18:54:33.525Z","dependency_job_id":null,"html_url":"https://github.com/quarkpunk/mongoose","commit_stats":null,"previous_names":["quarkpunk/mongoose"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quarkpunk/mongoose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quarkpunk%2Fmongoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quarkpunk%2Fmongoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quarkpunk%2Fmongoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quarkpunk%2Fmongoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quarkpunk","download_url":"https://codeload.github.com/quarkpunk/mongoose/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quarkpunk%2Fmongoose/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914931,"owners_count":22931334,"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":["cmake","cpp","json","mongocxx","mongodb","mongoose"],"created_at":"2025-06-15T03:13:28.469Z","updated_at":"2026-05-04T13:33:51.969Z","avatar_url":"https://github.com/quarkpunk.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoose (MongoDB C++)\nSimple and efficient C++ serializer/deserializer for BSON documents intended for MongoDB. The library implements work with (almost) all the basic types necessary for working with BSON and JSON structures\n\n✅ Convenient API\n- Easy to use\n- Models/Schemas\n\n📦 Dependencies\n- C++20\n- CMake\n- mongocxx (4.0.0)\n- boost.pfr (from mongocxx)\n\n## Types Serialization from JSON and BSON\nThese are the main data types this library can work with, specifically parsing and converting data between C++ and the BSON data format. Unfortunately, mongoose doesn't have its own JSON module for converting native BSON types into JSON string\n\n| Type | BSON | JSON | About |\n|---|---|---|---|\n| int 32/64     | ✅    | ✅    | numbers|\n| bool          | ✅    | ✅    | boolean |\n| float         | ✅    | ✅    | num float |\n| double        | ✅    | ✅    | num double |\n| string        | ✅    | ✅    | basic string |\n| array         | ✅    | ✅    | fixed array |\n| vector        | ✅    | ✅    | dynamic vector |\n| enum class    | ✅    | ✅    | enum class type |\n| optional      | ✅    | ✅    | value or null |\n| object        | ✅    | ✅    | nested object |\n| time_point    | ✅    | ✅    | date time value |\n| object_oid    | ✅    | ✅    | id object |\n| binary        | ...   | ...   | binary data |\n\n## How to use\nDownload the library in any way and place it in your project directory, include it in your CMake project\n```cmake\n# add library\nadd_subdirectory(${PROJECT_SOURCE_DIR}/lib/mongoose)\n\n# link library\ntarget_link_libraries(${PROJECT_NAME} PRIVATE\n    # dont link mongo::mongocxx_static\n    # mongoose alredy link mongocxx lib\n    mongoose\n)\n```\n\n## Model/Schema\nModels are created quite simply, it is enough to declare structures in the usual C++ form, and that's all\n\n```cpp\n// to make working with dates easier\nusing time_point = std::chrono::system_clock::time_point;\n\n// nested model/document\nstruct user_city{\n    std::string id;\n    std::string name;\n};\n// nested model/document\nstruct user_info{\n    int age;\n    std::string name;\n    std::optional\u003cuser_city\u003e city;\n    std::vector\u003cbsoncxx::oid\u003e tags;\n};\n// main user model/document\nstruct user{\n    bsoncxx::oid _id;\n    user_info info;\n    time_point created_at;\n    time_point updated_at;\n};\n```\nTo serialize your data into a BSON document, you need to\n```cpp\n// build BSON document value from struct\nauto doc = mongoose::to_bson(user_value);\n```\n```cpp\n// build BSON document without _id\n// if you need to insert/update the entire document\nauto doc = mongoose::to_bson_without_id(user_value);\nauto result = collection.insert_one(doc.view());\n```\n\n## JSON\nTo deserialize from JSON to BSON, for example, to retrieve from your frontend, use the `mongoose::from_json\u003cT\u003e(string)` method. The result will be an optional value `std::optional\u003cT\u003e`. If the JSON string is invalid, a `null` result will be returned\n```cpp\n// parse to \u003cT\u003e model from JSON string\n// return value if success parsing\n// and cast BSON value to \u003cT\u003e \nstd::optional\u003cuser\u003e value = mongoose::from_json\u003cuser\u003e(json_string);\n\n// check optional\n// failed, null value\nif(!value){\n    return;\n}\n```\n\nTo serialize pure JSON from your C++ struct, it's best to assemble the JSON manually using any C++ JSON library, such as `nlohmann_json`, this is a simplified code example\n```cpp\n// build handmade your JSON\nnlohmann::json user_json = {\n    { \"id\", user._id },\n    { \"info\", {\n        { \"age\", user.info.age },\n        { \"name\", user.info.name },\n        { \"city\", nullptr },\n        { \"tags\", nlohmann::json::array() },\n    }},\n    { \"updated_at\", user.updated_at },    \n    { \"created_at\", user.created_at },    \n}\n\n// export JSON to string\nstd::string result = user_json.dump();\n```\n\nAs a last resort, you can use the native `bsoncxx::to_json` method from the bsoncxx library to construct a JSON string from your BSON document\n```cpp\n// parse \u003cT\u003e model to BSON document value\nauto doc = mongoose::to_bson(user_value);\n// bsoncxx native method\n// build JSON string from BSON document\nstd::string result = bsoncxx::to_json(doc);\n```\n\nHowever, there's one important caveat. Your JSON will contain native BSON variable types, such as `$oid`, `$date`, and others. If this is acceptable to you, and the purity of your JSON isn't critical, then you can safely use `bsoncxx::to_json` method\n\n## Concept\nIn fact, I was tired of constantly writing the same code, so I wanted to template it and make it more accessible for writing my backend web applications without problems, I was inspired by the mongoose library in javascript and decided to write my own small version","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquarkpunk%2Fmongoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquarkpunk%2Fmongoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquarkpunk%2Fmongoose/lists"}