{"id":47207250,"url":"https://github.com/cloudresty/go-mongodb","last_synced_at":"2026-03-13T14:30:58.698Z","repository":{"id":303302664,"uuid":"1011291142","full_name":"cloudresty/go-mongodb","owner":"cloudresty","description":"A modern, production-ready Go package for MongoDB operations with environment-first configuration, ULID ObjectIDs, and comprehensive production features","archived":false,"fork":false,"pushed_at":"2026-03-09T03:16:11.000Z","size":313,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-09T08:27:32.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cloudresty.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudresty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-30T15:33:13.000Z","updated_at":"2026-03-09T03:13:39.000Z","dependencies_parsed_at":"2025-07-06T22:34:09.048Z","dependency_job_id":"e5eae9b3-5218-42cd-9f0a-d7c0f462f53e","html_url":"https://github.com/cloudresty/go-mongodb","commit_stats":null,"previous_names":["cloudresty/go-mongodb"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/cloudresty/go-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudresty%2Fgo-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudresty%2Fgo-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudresty%2Fgo-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudresty%2Fgo-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudresty","download_url":"https://codeload.github.com/cloudresty/go-mongodb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudresty%2Fgo-mongodb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30468266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T11:00:43.441Z","status":"ssl_error","status_checked_at":"2026-03-13T11:00:23.173Z","response_time":60,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-03-13T14:30:57.819Z","updated_at":"2026-03-13T14:30:58.656Z","avatar_url":"https://github.com/cloudresty.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go MongoDB\n\n[Home](README.md) \u0026nbsp;/\n\n\u0026nbsp;\n\nA modern, production-ready Go package for MongoDB operations with environment-first configuration, ULID IDs, and comprehensive production features.\n\n\u0026nbsp;\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/cloudresty/go-mongodb/v2.svg)](https://pkg.go.dev/github.com/cloudresty/go-mongodb/v2)\n[![Go Tests](https://github.com/cloudresty/go-mongodb/actions/workflows/ci.yaml/badge.svg)](https://github.com/cloudresty/go-mongodb/actions/workflows/ci.yaml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/cloudresty/go-mongodb/v2)](https://goreportcard.com/report/github.com/cloudresty/go-mongodb/v2)\n[![GitHub Tag](https://img.shields.io/github/v/tag/cloudresty/go-mongodb?label=Version)](https://github.com/cloudresty/go-mongodb/tags)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n\u0026nbsp;\n\n## Table of Contents\n\n- [Key Features](#key-features)\n- [Quick Start](#quick-start)\n  - [Installation](#installation)\n  - [Basic Usage](#basic-usage)\n  - [Environment Configuration](#environment-configuration)\n- [Documentation](#documentation)\n- [Why This Package?](#why-this-package)\n- [Production Usage](#production-usage)\n- [Requirements](#requirements)\n- [Contributing](#contributing)\n- [Security](#security)\n- [License](#license)\n\n\u0026nbsp;\n\n## Key Features\n\n- **Environment-First**: Configure via environment variables for cloud-native deployments\n- **ULID IDs**: 6x faster generation, database-optimized, lexicographically sortable\n- **Zero-Allocation ID Injection**: Best-in-class performance for struct inserts\n- **Production-Ready**: Graceful shutdown, timeouts, health checks, transaction support\n- **Type-Safe API**: Strict validation prevents data corruption\n- **Pluggable Logging**: Silent by default, integrate with any logging framework\n- **Command Monitoring**: Built-in APM support for Datadog, OpenTelemetry, etc.\n- **Fully Tested**: Comprehensive test coverage with CI/CD pipeline\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Quick Start\n\n\u0026nbsp;\n\n### Installation\n\n```bash\ngo get github.com/cloudresty/go-mongodb/v2\n```\n\n\u003e **Note**: This is v2 of the library. For migration from v1, see [Migration Guide](docs/migration-v2.md).\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### Basic Usage\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n    \"github.com/cloudresty/go-mongodb/v2\"\n    \"github.com/cloudresty/go-mongodb/v2/filter\"\n    \"github.com/cloudresty/go-mongodb/v2/update\"\n)\n\ntype User struct {\n    Name   string `bson:\"name\" json:\"name\"`\n    Email  string `bson:\"email\" json:\"email\"`\n    Status string `bson:\"status\" json:\"status\"`\n}\n\nfunc main() {\n    // Client - uses MONGODB_* environment variables\n    client, err := mongodb.NewClient()\n    if err != nil {\n        panic(err)\n    }\n    defer client.Close()\n\n    // Insert a document with auto-generated ULID ID using type-safe struct\n    collection := client.Collection(\"users\")\n    user := User{\n        Name:  \"John Doe\",\n        Email: \"john@example.com\",\n    }\n\n    result, err := collection.InsertOne(context.Background(), user)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Find documents using type-safe filter\n    var foundUser User\n    err = collection.FindOne(context.Background(),\n        filter.Eq(\"email\", \"john@example.com\")).Decode(\u0026foundUser)\n    if err != nil {\n        log.Fatal(err)\n    }\n\n    // Update documents using type-safe update builder\n    _, err = collection.UpdateOne(context.Background(),\n        filter.Eq(\"email\", \"john@example.com\"),\n        update.Set(\"status\", \"active\"))\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n```\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### Environment Configuration\n\nSet environment variables for your deployment:\n\n```bash\nexport MONGODB_HOSTS=localhost:27017\nexport MONGODB_DATABASE=myapp\nexport MONGODB_CONNECTION_NAME=my-service\n```\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Documentation\n\n| Document | Description |\n| :--- | :--- |\n| [Getting Started](docs/getting-started.md) | Quick start guide and installation instructions |\n| [Migration Guide v2](docs/migration-v2.md) | Migrating from v1 to v2 |\n| [API Reference](docs/api-reference.md) | Complete function reference and usage patterns |\n| [Environment Variables](docs/environment-variables.md) | Supported variables and their purpose |\n| [Environment Configuration](docs/environment-configuration.md) | Environment variables and deployment configurations |\n| [Production Features](docs/production-features.md) | Graceful shutdown, health checks, transactions |\n| [ID Generation](docs/id-generation.md) | High-performance, database-optimized document identifiers |\n| [Examples](docs/examples.md) | Comprehensive examples and usage patterns |\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Why This Package?\n\nThis package is designed for modern cloud-native applications that require robust, high-performance MongoDB operations. It leverages the power of MongoDB while providing a developer-friendly API that integrates seamlessly with environment-based configurations.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### Environment-First Design\n\nPerfect for modern cloud deployments with Docker, Kubernetes, and CI/CD pipelines. No more hardcoded connection strings.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### ULID IDs\n\nGet 6x faster document ID generation with better database performance compared to UUIDs. Natural time-ordering and collision resistance.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### Production-Ready\n\nBuilt-in support for high availability, graceful shutdown, automatic reconnection, and comprehensive timeout controls.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n### Performance Optimized\n\nPluggable logging framework, efficient ULID generation, and optimized for high-throughput scenarios.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Production Usage\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n    \"time\"\n    \"github.com/cloudresty/go-mongodb/v2\"\n)\n\nfunc main() {\n    // Use custom environment prefix for multi-service deployments\n    client, err := mongodb.NewClient(mongodb.FromEnvWithPrefix(\"PAYMENTS_\"))\n    if err != nil {\n        log.Fatal(err)\n    }\n    defer client.Close()\n\n    // Or configure with custom logger (silent by default)\n    // client, err := mongodb.NewClient(\n    //     mongodb.FromEnv(),\n    //     mongodb.WithLogger(yourCustomLogger), // Implement mongodb.Logger interface\n    // )\n\n    // Health checks and monitoring - use Ping to verify connectivity\n    if err := client.Ping(context.Background()); err != nil {\n        log.Fatalf(\"Health check failed: MongoDB is not reachable: %v\", err)\n    }\n    log.Println(\"Health check passed: MongoDB is reachable.\")\n\n    // For detailed metrics, get the stats\n    stats := client.Stats()\n    log.Printf(\"Client stats: %+v\", stats)\n\n    // Graceful shutdown with signal handling\n    shutdownManager := mongodb.NewShutdownManager(\u0026mongodb.ShutdownConfig{\n        Timeout: 30 * time.Second,\n    })\n    shutdownManager.SetupSignalHandler()\n    shutdownManager.Register(client)\n    shutdownManager.Wait() // Blocks until SIGINT/SIGTERM\n}\n```\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Requirements\n\n- Go 1.24+ (recommended)\n- MongoDB 8.0+ (recommended)\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for your changes\n4. Ensure all tests pass\n5. Submit a pull request\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## Security\n\nIf you discover a security vulnerability, please report it via email to [security@cloudresty.com](mailto:security@cloudresty.com).\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.\n\n\u0026nbsp;\n\n🔝 [back to top](#go-mongodb)\n\n\u0026nbsp;\n\n\u0026nbsp;\n\n---\n\n### Cloudresty\n\n[Website](https://cloudresty.com) \u0026nbsp;|\u0026nbsp; [LinkedIn](https://www.linkedin.com/company/cloudresty) \u0026nbsp;|\u0026nbsp; [BlueSky](https://bsky.app/profile/cloudresty.com) \u0026nbsp;|\u0026nbsp; [GitHub](https://github.com/cloudresty) \u0026nbsp;|\u0026nbsp; [Docker Hub](https://hub.docker.com/u/cloudresty)\n\n\u003csub\u003e\u0026copy; Cloudresty\u003c/sub\u003e\n\n\u0026nbsp;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudresty%2Fgo-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudresty%2Fgo-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudresty%2Fgo-mongodb/lists"}