{"record":{"id":"f7cb3180378faea6","repo":"golang-migrate/migrate","slug":"no-config-f7cb31","errorCode":null,"errorMessage":"no config","messagePattern":"no config","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"database/mongodb/mongodb.go","lineNumber":40,"sourceCode":"func init() {\n\tdb := Mongo{}\n\tdatabase.Register(\"mongodb\", &db)\n\tdatabase.Register(\"mongodb+srv\", &db)\n}\n\nvar DefaultMigrationsCollection = \"schema_migrations\"\n\nconst DefaultLockingCollection = \"migrate_advisory_lock\" // the collection to use for advisory locking by default.\nconst lockKeyUniqueValue = 0                             // the unique value to lock on. If multiple clients try to insert the same key, it will fail (locked).\nconst DefaultLockTimeout = 15                            // the default maximum time to wait for a lock to be released.\nconst DefaultLockTimeoutInterval = 10                    // the default maximum intervals time for the locking timout.\nconst DefaultAdvisoryLockingFlag = true                  // the default value for the advisory locking feature flag. Default is true.\nconst LockIndexName = \"lock_unique_key\"                  // the name of the index which adds unique constraint to the locking_key field.\nconst contextWaitTimeout = 5 * time.Second               // how long to wait for the request to mongo to block/wait for.\n\nvar (\n\tErrNoDatabaseName            = fmt.Errorf(\"no database name\")\n\tErrNilConfig                 = fmt.Errorf(\"no config\")\n\tErrLockTimeoutConfigConflict = fmt.Errorf(\"both x-advisory-lock-timeout-interval and x-advisory-lock-timout-interval were specified\")\n)\n\ntype Mongo struct {\n\tclient   *mongo.Client\n\tdb       *mongo.Database\n\tconfig   *Config\n\tisLocked atomic.Bool\n}\n\ntype Locking struct {\n\tCollectionName string\n\tTimeout        int\n\tEnabled        bool\n\tInterval       int\n}\ntype Config struct {\n\tDatabaseName         string","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/golang-migrate/migrate/blob/01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a/database/mongodb/mongodb.go#L22-L58","documentation":"ErrNilConfig in database/mongodb is returned by WithInstance, WithConnection and extractCustomQueryParams when the *Config argument is nil. The Mongo driver requires a Config to hold DatabaseName and options like transaction mode and advisory lock settings. It is a programming/configuration guard, not a server error.","triggerScenarios":"mongodb.WithInstance(client, nil); mongodb.WithConnection(ctx, db, nil); nil config reaching extractCustomQueryParams via Open.","commonSituations":"Typed-nil *mongodb.Config passed in, wrapper helpers that drop nil configs, refactors where WithConfig was removed but call sites still pass nil.","solutions":["Pass a non-nil *mongodb.Config to WithInstance/WithConnection","Use mongodb.WithConnection with a config built from WithConfig-style construction","Nil-check the config in your bootstrap code before creating the driver"],"exampleFix":"// before\nd, err := mongodb.WithInstance(ctx, client, nil)\n// after\ncfg := &mongodb.Config{DatabaseName: \"mydb\"}\nd, err := mongodb.WithInstance(ctx, client, cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return fmt.Errorf(\"mongodb migration requires non-nil *mongodb.Config\")\n}","typeGuard":"func hasMongoConfig(cfg *mongodb.Config) bool { return cfg != nil }","tryCatchPattern":"if err != nil {\n    if errors.Is(err, mongodb.ErrNilConfig) {\n        return fmt.Errorf(\"driver bootstrap bug: nil mongo config\")\n    }\n    return err\n}","preventionTips":["Construct Config in one factory function so nils cannot escape","Avoid declaring `var cfg *mongodb.Config` without assignment","Add a constructor unit test that exercises the nil path"],"tags":["go","golang-migrate","mongodb","config","nil-pointer"],"backgroundTag":"nil-config-passed-to-driver","analyzedSha":"01a9643f1475e75bb6d6224ddeaf9d8e2434ca8a","analyzedAt":"2026-09-02T19:38:29.671Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}