A Go ODM for MongoDB that adds object-document mapping, hooks, validation, and cascade support to mgo.
Bongo is an Object-Document Mapper (ODM) for MongoDB, built as a wrapper around the mgo driver for Go. It provides structured document handling with Go structs, lifecycle hooks, validation, and cascade operations to simplify MongoDB interactions while maintaining access to low-level operations.
Go developers building applications with MongoDB who need a higher-level abstraction for data modeling, validation, and relationship management without losing direct database access.
Developers choose Bongo for its robust feature set—including hooks, validation, cascade saves/deletes, and change tracking—that fills the gap for a full-featured ODM in Go, offering convention-based simplicity alongside the flexibility to drop down to raw mgo queries when needed.
Go ODM for MongoDB
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Bongo provides BeforeSave, AfterSave, BeforeDelete, AfterDelete, AfterFind, and Validate hooks, allowing custom logic injection at key document lifecycle stages, as detailed in the hooks section of the README.
It includes an integrated validation system that returns structured ValidationError objects, making error handling and display straightforward, as shown in the saving models example with type assertion.
Offers diff tracking via the Trackable interface to monitor field modifications, useful for auditing or conditional updates, with practical examples in the change tracking section.
Maintains full access to the underlying mgo driver, enabling developers to drop down to raw MongoDB queries when needed, as highlighted in the philosophy and usage with connection.Session.
Supports cascade save and delete for data integrity across related documents, though unstable, with detailed CascadeConfig setup examples in the README.
The cascade functionality is labeled unstable in the README and may require refactoring, posing risks for production environments where data consistency is critical.
Bongo is built on the mgo driver, which is older and might not integrate well with modern Go modules or support the latest MongoDB advancements, limiting future-proofing.
Setting up cascade operations involves verbose CascadeConfig structs and manual diff tracking, increasing development complexity and potential for errors, as seen in the cascade example.
Lacks mention of support for newer MongoDB features like transactions or aggregation pipelines in its ODM layer, requiring fallback to raw mgo which may be cumbersome.