diff --git a/main.go b/main.go index c095922..272e623 100644 --- a/main.go +++ b/main.go @@ -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 } - sys.OnExit(func () { - if err := client.Client.Disconnect(context.TODO()); err != nil { - log.Fatalf("failed to disconnect: %v", err) - } - }) + if props.AutoCleanup { + sys.OnExit(func () { + if err := Stop(); err != nil { + log.Fatalf("failed to disconnect: %v", err) + } + }) + } // Register defaults.go var structfulDef bson.M