Add AutoCleanup in configuration

This commit is contained in:
George Suntres
2026-04-27 13:54:51 -04:00
parent 40ce8d334b
commit 1142585f84

View File

@@ -315,6 +315,7 @@ type MongoStartProps struct {
MongoDBPrefix string
ContextFields []string
WithAudit bool
AutoCleanup bool
OnAudit *OnAudit
AllowTruncatingDoubles bool
}
@@ -410,11 +411,13 @@ func Start(props *MongoStartProps) error {
return err
}
if props.AutoCleanup {
sys.OnExit(func () {
if err := client.Client.Disconnect(context.TODO()); err != nil {
if err := Stop(); err != nil {
log.Fatalf("failed to disconnect: %v", err)
}
})
}
// Register defaults.go
var structfulDef bson.M