{"id":16108456,"url":"https://github.com/chidiwilliams/flatbson","last_synced_at":"2025-03-16T08:32:36.585Z","repository":{"id":54376182,"uuid":"265214088","full_name":"chidiwilliams/flatbson","owner":"chidiwilliams","description":"Recursively flatten a Go struct using its BSON tags","archived":false,"fork":false,"pushed_at":"2022-11-14T04:04:25.000Z","size":34,"stargazers_count":67,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-27T05:56:09.108Z","etag":null,"topics":["bson","go","golang","mongo"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/chidiwilliams/flatbson","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/chidiwilliams.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-05-19T10:16:15.000Z","updated_at":"2024-11-27T17:43:34.000Z","dependencies_parsed_at":"2023-01-22T00:48:39.192Z","dependency_job_id":null,"html_url":"https://github.com/chidiwilliams/flatbson","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chidiwilliams%2Fflatbson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chidiwilliams%2Fflatbson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chidiwilliams%2Fflatbson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chidiwilliams%2Fflatbson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chidiwilliams","download_url":"https://codeload.github.com/chidiwilliams/flatbson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243807355,"owners_count":20350989,"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","go","golang","mongo"],"created_at":"2024-10-09T19:26:52.380Z","updated_at":"2025-03-16T08:32:36.170Z","avatar_url":"https://github.com/chidiwilliams.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FlatBSON\n\n[![Build status](https://github.com/chidiwilliams/flatbson/workflows/Build/badge.svg)](https://github.com/chidiwilliams/flatbson/actions?query=workflow%3ABuild) [![API reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/chidiwilliams/flatbson?tab=doc) [![codecov](https://codecov.io/gh/chidiwilliams/flatbson/branch/master/graph/badge.svg)](https://codecov.io/gh/chidiwilliams/flatbson)\n\nFlatBSON recursively flattens a Go struct using its BSON tags.\n\nIt is particularly useful for partially updating embedded Mongo documents.\n\nFor example, to update a `User`'s `Address.Visited` field, first call `flatbson.Flatten` with the parent struct:\n\n```go\ntype User struct {\n  ID      bson.ObjectID `bson:\"_id,omitempty\"`\n  Name    string        `bson:\"name,omitempty\"`\n  Address Address       `bson:\"address,omitempty\"`\n}\n\ntype Address struct {\n  Street    string    `bson:\"street,omitempty\"`\n  City      string    `bson:\"city,omitempty\"`\n  State     string    `bson:\"state,omitempty\"`\n  VisitedAt time.Time `bson:\"visitedAt,omitempty\"`\n}\n\nflatbson.Flatten(User{Address: {VisitedAt: time.Now().UTC()}})\n\n// Result:\n// map[string]interface{}{\"address.visitedAt\": time.Time{...}}\n```\n\nPassing the result to `coll.UpdateOne` updates only the `address.VisitedAt` field instead of overwriting the entire `address` embedded document. See this [blog post](https://dev.to/chidiwilliams/partially-updating-an-embedded-mongo-document-in-go-knn) for more information.\n\nThe complete documentation is available on [Godoc](https://pkg.go.dev/github.com/chidiwilliams/flatbson).\n\n## How to Install\n\n```shell script\ngo get -v github.com/chidiwilliams/flatbson\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchidiwilliams%2Fflatbson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchidiwilliams%2Fflatbson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchidiwilliams%2Fflatbson/lists"}