{"id":16216270,"url":"https://github.com/matthewhartstonge/mongo-features","last_synced_at":"2026-05-02T03:31:16.947Z","repository":{"id":57541655,"uuid":"291861757","full_name":"matthewhartstonge/mongo-features","owner":"matthewhartstonge","description":"Extend mongo-go-driver with feature detection!","archived":false,"fork":false,"pushed_at":"2020-09-02T23:15:07.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-07T22:43:18.175Z","etag":null,"topics":["feature-detection","go","golang","mongo"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matthewhartstonge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-01T01:11:33.000Z","updated_at":"2020-09-02T23:15:09.000Z","dependencies_parsed_at":"2022-09-09T02:50:12.634Z","dependency_job_id":null,"html_url":"https://github.com/matthewhartstonge/mongo-features","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/matthewhartstonge/mongo-features","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewhartstonge%2Fmongo-features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewhartstonge%2Fmongo-features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewhartstonge%2Fmongo-features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewhartstonge%2Fmongo-features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matthewhartstonge","download_url":"https://codeload.github.com/matthewhartstonge/mongo-features/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matthewhartstonge%2Fmongo-features/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32522219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["feature-detection","go","golang","mongo"],"created_at":"2024-10-10T11:18:55.591Z","updated_at":"2026-05-02T03:31:16.929Z","avatar_url":"https://github.com/matthewhartstonge.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongo-features\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/matthewhartstonge/mongo-features)](https://pkg.go.dev/github.com/matthewhartstonge/mongo-features) [![Go Report Card](https://goreportcard.com/badge/github.com/matthewhartstonge/mongo-features)](https://goreportcard.com/report/github.com/matthewhartstonge/mongo-features)\n\nThe official mongo driver is great - but it's a bit more low level than the mgo\ncommunity driver, so we need to check whether certain mongo features can be \nused. \n\nEnter `mongo (feat. features)`.\n\n\u003e Session detection requires the consumer to have `clusterMonitor` mongodb permissions.\n\u003e Sessions should work on a single node, but there is [an in progress fix for this](https://github.com/mongodb/mongo-go-driver/pull/497).\n\n## tl;dr\nRefer: [_examples/tldr](./_examples/tldr)\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/matthewhartstonge/mongo-features\"\n\t\"go.mongodb.org/mongo-driver/mongo\"\n)\n\nfunc main() {\n\tctx := context.Background()\n\tclient, err := mongo.Connect(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfeatureSet := features.New(client)\n\tfmt.Printf(\"I am running on mongo major version: %d\\n\", featureSet.MongoVersion.Major())\n\tfmt.Printf(\"I am running on mongo minor version: %d\\n\", featureSet.MongoVersion.Minor())\n\tfmt.Printf(\"I am running on mongo version: %s\\n\", featureSet.MongoVersion.String())\n\tfmt.Printf(\"I can perform server sessions: %t\\n\", featureSet.HasSessions)\n\tfmt.Printf(\"I can perform multi-document acid transactions: %t\\n\", featureSet.HasTransactions)\n}\n```\n\n## Made for Plug'n'Play\nWhen creating your own mongo datastore API, you can plug this bad boy into your structs:\n\nRefer: [_examples/plugnplay](./_examples/plugnplay)\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\tfeat \"github.com/matthewhartstonge/mongo-features\"\n\t\"go.mongodb.org/mongo-driver/mongo\"\n)\n\ntype Store struct {\n\tdb *mongo.Database\n\n\t*feat.Features\n}\n\ntype thing struct {\n\tName string\n}\n\nfunc (s *Store) CreateThing(ctx context.Context, thing1 thing) {\n\tif s.HasSessions {\n\t\tsess, err := s.db.Client().StartSession()\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tctx = mongo.NewSessionContext(ctx, sess)\n\t\tdefer sess.EndSession(ctx)\n\t}\n\n\t// like, totally put your transact-able actions in here...\n}\n\nfunc New() *Store {\n\tctx := context.Background()\n\tclient, err := mongo.Connect(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\ttestDb := client.Database(\"test\")\n\treturn \u0026Store{\n\t\tdb:       testDb,\n\t\tFeatures: feat.New(client),\n\t}\n}\n\nfunc main() {\n\tstore := New()\n\tfmt.Printf(\"My datastore is running on mongo major version: %d\\n\", store.MongoVersion.Major())\n\tfmt.Printf(\"My datastore is running on mongo minor version: %d\\n\", store.MongoVersion.Minor())\n\tfmt.Printf(\"My datastore is running on mongo version: %s\\n\", store.MongoVersion.String())\n\tfmt.Printf(\"My datastore can perform server sessions: %t\\n\", store.HasSessions)\n\tfmt.Printf(\"My datastore can perform multi-document acid transactions: %t\\n\", store.HasTransactions)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewhartstonge%2Fmongo-features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatthewhartstonge%2Fmongo-features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatthewhartstonge%2Fmongo-features/lists"}