{"id":"ab8b4a22774bc483","repo":"mongodb/node-mongodb-native","slug":"the-callback-form-of-this-helper-has-been-removed","errorCode":null,"errorMessage":"The callback form of this helper has been removed.","messagePattern":"The callback form of this helper has been removed\\.","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/db.ts","lineNumber":327,"sourceCode":"  /** Return the Admin db instance */\n  admin(): Admin {\n    return new Admin(this);\n  }\n\n  /**\n   * Returns a reference to a MongoDB Collection. If it does not exist it will be created implicitly.\n   *\n   * Collection namespace validation is performed server-side.\n   *\n   * @param name - the collection name we wish to access.\n   * @returns return the new Collection instance\n   */\n  collection<TSchema extends Document = Document>(\n    name: string,\n    options: CollectionOptions = {}\n  ): Collection<TSchema> {\n    if (typeof options === 'function') {\n      throw new MongoInvalidArgumentError('The callback form of this helper has been removed.');\n    }\n    return new Collection<TSchema>(this, name, resolveOptions(this, options));\n  }\n\n  /**\n   * Get all the db statistics.\n   *\n   * @param options - Optional settings for the command\n   */\n  async stats(options?: DbStatsOptions): Promise<Document> {\n    return await executeOperation(\n      this.client,\n      new DbStatsOperation(this, resolveOptions(this, options))\n    );\n  }\n\n  /**\n   * List all collections of this database with optional filter","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/db.ts#L309-L345","documentation":"The driver removed callback-style APIs in major version 5. db.collection() now requires options to be a plain object; the legacy signature db.collection(name, callback) is detected (options is a function) and rejected. Use the synchronous promise-based API instead — db.collection() is already non-async.","triggerScenarios":"Calling db.collection('users', cb) or passing a function as the second argument, typical of mongodb v4 (and earlier) callback code.","commonSituations":"Upgrading from mongodb v4 to v5+; copy-pasting legacy tutorial code; partial migrations that left callback call sites.","solutions":["Remove the callback — db.collection() returns the Collection synchronously, no awaiting needed","Pass options as an object, never a function","Run the v4-to-v5 migration guide over every callback call site"],"exampleFix":"// before\ndb.collection('users', (err, coll) => { /* ... */ });\n// after\nconst coll = db.collection('users');","handlingStrategy":"validation","validationCode":"function getCollection(db, name, options) {\n  if (typeof options === 'function') {\n    throw new Error('Callback form removed in v5; use the synchronous return value');\n  }\n  return db.collection(name, options);\n}","typeGuard":"function isPlainOptions(o: unknown): o is Record<string, unknown> {\n  return o == null || (typeof o === 'object' && typeof (o as any).then !== 'function');\n}","tryCatchPattern":null,"preventionTips":["Audit callback-style call sites when upgrading major versions","Use promise-returning signatures exclusively","Lint for function arguments to db.collection()"],"tags":["db","callback","migration","api-breaking-change"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}