{"record":{"id":"4df5ad2a9f897fe6","repo":"mongodb/node-mongodb-native","slug":"collection-this-namespace-not-found","errorCode":null,"errorMessage":"collection ${this.namespace} not found","messagePattern":"collection (.+?) not found","errorType":"exception","errorClass":"MongoAPIError","httpStatus":null,"severity":"error","filePath":"src/collection.ts","lineNumber":592,"sourceCode":"      this.s.namespace,\n      filter,\n      resolveOptions(this, options)\n    );\n  }\n\n  /**\n   * Returns the options of the collection.\n   *\n   * @param options - Optional settings for the command\n   */\n  async options(options?: OperationOptions): Promise<Document> {\n    options = resolveOptions(this, options);\n    const [collection] = await this.db\n      .listCollections({ name: this.collectionName }, { ...options, nameOnly: false })\n      .toArray();\n\n    if (collection == null || collection.options == null) {\n      throw new MongoAPIError(`collection ${this.namespace} not found`);\n    }\n\n    return collection.options;\n  }\n\n  /**\n   * Returns if the collection is a capped collection\n   *\n   * @param options - Optional settings for the command\n   */\n  async isCapped(options?: OperationOptions): Promise<boolean> {\n    const { capped } = await this.options(options);\n    return Boolean(capped);\n  }\n\n  /**\n   * Creates an index on the db and collection collection.\n   *","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/collection.ts#L574-L610","documentation":"Thrown by Collection.options when listCollections does not return a document (or a document without options) for the collection name. It runs db.listCollections filtered by name and, if nothing matches, raises a MongoAPIError that the collection was not found. This is a runtime/server-state condition, not an argument-type error.","triggerScenarios":"Fires at src/collection.ts:592 when the filtered listCollections cursor yields no document or one whose options field is null/undefined. Called by collection.options() and indirectly by isCapped and other metadata-dependent methods.","commonSituations":"Calling .options() on a collection that has never been created (MongoDB creates lazily on first write, so a write-less collection may not exist); connecting to the wrong database; insufficient permissions to list collections (auth); the collection was dropped between calls; a typo in the collection name.","solutions":["Ensure the collection exists by performing a write first or running createCollection.","Verify the database name and collection name in the MongoClient URI/hierarchy.","Check that the authenticated user has listCollections privileges.","Guard the call with a check or create the collection explicitly if optional."],"exampleFix":"// before\nconst opts = await db.collection('maybeMissing').options();\n\n// after\nconst coll = db.collection('maybeMissing');\ntry {\n  return await coll.options();\n} catch (e) {\n  if (e instanceof MongoAPIError && /not found/.test(e.message)) return null;\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const exists = await db.listCollections({ name: coll.collectionName }, { nameOnly: true }).hasNext();\nif (!exists) return null;\nreturn await coll.options();","typeGuard":null,"tryCatchPattern":"try {\n  return await coll.options();\n} catch (e) {\n  if (e instanceof MongoAPIError && /not found/.test(e.message)) return null;\n  throw e;\n}","preventionTips":["Ensure the collection exists (write to it or createCollection) before calling .options().","Verify database name and authenticated user's listCollections permission.","Treat .options() as optional when the collection may not exist yet."],"tags":["metadata","server-state","auth","configuration"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}