{"id":15724222,"url":"https://github.com/codeation/nosql","last_synced_at":"2026-05-14T20:03:19.396Z","repository":{"id":144205340,"uuid":"172339689","full_name":"codeation/nosql","owner":"codeation","description":"A wrapper to make it easier to use go.mongodb.org/mongo-driver","archived":false,"fork":false,"pushed_at":"2024-12-12T03:17:10.000Z","size":32,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-22T15:07:24.886Z","etag":null,"topics":["go","golang","golang-library","library","mongo","mongodb","mongodb-driver","mongodb-go-driver"],"latest_commit_sha":null,"homepage":"","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/codeation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-24T13:17:02.000Z","updated_at":"2024-12-12T03:16:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"2a991b83-330e-4d0b-abe2-879f18e37a59","html_url":"https://github.com/codeation/nosql","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/codeation/nosql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeation%2Fnosql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeation%2Fnosql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeation%2Fnosql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeation%2Fnosql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeation","download_url":"https://codeload.github.com/codeation/nosql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeation%2Fnosql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33041204,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"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":["go","golang","golang-library","library","mongo","mongodb","mongodb-driver","mongodb-go-driver"],"created_at":"2024-10-03T22:15:37.477Z","updated_at":"2026-05-14T20:03:19.330Z","avatar_url":"https://github.com/codeation.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nosql\nA wrapper to make it easier to use go.mongodb.org/mongo-driver/v2\n\n[![PkgGoDev](https://pkg.go.dev/badge/codeation/nosql/v2)](https://pkg.go.dev/github.com/codeation/nosql/v2)\n\n## FindMany(...).Decode(...) chain\n\nYou can use the FindMany Decode chain to decode an array of documents from mongodb collection.\n\n```\n\tcollection := client.Database(\"test\").Collection(\"test\")\n\n\tvar data []Elem\n\tif err := nosql.FindMany(ctx, collection, bson.D{}).Decode(\u0026data); err != nil {\n\t\treturn err\n\t}\n\n\t// Some using of documents slice\n\tfor _, e := range data {\n\t\tfmt.Println(e.ID)\n\t}\n\n```\n\nIt is like calling FindOne Decode chain to decode a single document in a\n[standard mongodb driver](https://godoc.org/go.mongodb.org/mongo-driver/v2/mongo).\n\nFindMany wraps the\n[func (*Collection) Find](https://godoc.org/go.mongodb.org/mongo-driver/v2/mongo#Collection.Find)\nresults, so the parameters are the same.\n\nData parameter of func Decode may be a pointer to an slice of struct.\nAlso data parameter may be a pointer to an slice of pointers to a struct, see below.\n\nIf no documents are found, an empty slice is returned.\n\n## Minimal example\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/codeation/nosql/v2\"\n\t\"go.mongodb.org/mongo-driver/v2/bson\"\n\t\"go.mongodb.org/mongo-driver/v2/mongo\"\n\t\"go.mongodb.org/mongo-driver/v2/mongo/options\"\n)\n\ntype Elem struct {\n\tNum int    `bson:\"num\"`\n\tStr string `bson:\"str\"`\n}\n\nfunc main() {\n\tclient, err := mongo.NewClient(options.Client().ApplyURI(\"mongodb://localhost:27017/\"))\n\tif err != nil {\n\t\treturn\n\t}\n\n\tctx := context.Background()\n\tif err = client.Connect(ctx); err != nil {\n\t\treturn\n\t}\n\tdefer client.Disconnect(ctx)\n\n\tcollection := client.Database(\"test\").Collection(\"test\")\n\n\tvar data []*Elem\n\tif err := nosql.FindMany(ctx, collection, bson.D{}).Decode(\u0026data); err != nil {\n\t\treturn\n\t}\n\n\tfor _, e := range data {\n\t\tfmt.Println(e.Num, e.Str)\n\t}\n}\n```\n\n## Wrapper example\n\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/codeation/nosql/v2\"\n\t\"go.mongodb.org/mongo-driver/v2/bson\"\n\t\"go.mongodb.org/mongo-driver/v2/mongo\"\n\t\"go.mongodb.org/mongo-driver/v2/mongo/options\"\n)\n\ntype Elem struct {\n\tNum int    `bson:\"num\"`\n\tStr string `bson:\"str\"`\n}\n\nfunc main() {\n\tclient, err := mongo.NewClient(options.Client().ApplyURI(\"mongodb://localhost:27017/\"))\n\tif err != nil {\n\t\treturn\n\t}\n\n\tctx := context.Background()\n\tif err = client.Connect(ctx); err != nil {\n\t\treturn\n\t}\n\tdefer client.Disconnect(ctx)\n\n\tdb := nosql.NewDatabase(client.Database(\"test\")) // wrap mongo.Database reference\n\tcollection := db.Collection(\"test\")\n\n\tvar data []*Elem\n\tif err := collection.FindMany(ctx, bson.D{}).Decode(\u0026data); err != nil {\n\t\treturn\n\t}\n\n\tfor _, e := range data {\n\t\tfmt.Println(e.Num, e.Str)\n\t}\n}\n```\n\n## AggregateMany(...).Decode(...) chain\n\nYou can use the AggregateMany Decode chain to decode an array of documents from aggregate command results.\n\n```\n\tcollection := client.Database(\"test\").Collection(\"test\")\n\n\tvar data []Elem\n\tif err := nosql.AggregateMany(ctx, collection, bson.D{}).Decode(\u0026data); err != nil {\n\t\treturn err\n\t}\n```\n\n## NextSequence func\n\nNextSequence returns next ID value.\n\n```\n    id, err := db.NextSequence(ctx, \"elemid\")\n    if err != nil {\n        return err\n    }\n    e := \u0026Element {\n        ID: id,\n        ... // Other fields\n    }\n```\n\nThis can be useful when you plan to use int64 values as IDs,\nor you need to know the new ID before inserting the document.\n\nNextSequence uses the atomic operation\n[$inc](https://docs.mongodb.com/manual/reference/operator/update/inc/).\n\nMake sure that the \"counters\" collection has an index by \"id\" field:\n\n```\ndb.counters.createIndex( { id: 1 } )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeation%2Fnosql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeation%2Fnosql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeation%2Fnosql/lists"}