Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
mongoHandler
✓ import { mongoHandler } from '#mongodb-atlas-nuxt'
✗ import { mongoHandler } from 'mongodb-atlas-nuxt'
The import uses a Nuxt alias '#mongodb-atlas-nuxt', not the package name directly. This alias is provided by the module after installation and configuration in nuxt.config.ts.
MongoResponse (type)
✓ import type { MongoResponse } from '#mongodb-atlas-nuxt'
TypeScript types are exported. Use import type for type-only imports. The symbol may also include specific response shapes from methods.
default export
✓ import { defineNuxtModule } from 'nuxt' // not relevant; module auto-registers
✗ import mongodbAtlasNuxt from 'mongodb-atlas-nuxt'
This package only exports named exports, no default export. The module should be added to `modules` in nuxt.config, not imported directly.
Configures the module, imports the handler, and performs a findOne query. Shows the essential setup for Nuxt 3 and MongoDB Atlas API interaction.
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['mongodb-atlas-nuxt'],
mongodbAtlas: {
publicApiKey: process.env.ATLAS_PUBLIC_KEY ?? '',
privateApiKey: process.env.ATLAS_PRIVATE_KEY ?? '',
groupId: process.env.ATLAS_GROUP_ID ?? '',
clusterName: process.env.ATLAS_CLUSTER_NAME ?? '',
baseUrl: 'https://cloud.mongodb.com/api/atlas/v1.0'
}
});
// In a server route: server/api/test.get.ts
import { mongoHandler } from '#mongodb-atlas-nuxt';
export default defineEventHandler(async (event) => {
const mongo = await mongoHandler('myDatabase', 'myCollection');
const query = { filter: { _id: { $oid: '60d5f484f1a2c8b1f8e4e1a1' } } };
const doc = await mongo.findOne(query);
return { doc };
});
Errors
Common errors & fixes
Cannot find module '#mongodb-atlas-nuxt'
The module is not installed or not added to `modules` in nuxt.config.ts.
fixRun `npm install mongodb-atlas-nuxt` and add `'mongodb-atlas-nuxt'` to the `modules` array in nuxt.config.ts.
TypeError: (0 , #mongodb-atlas-nuxt.mongoHandler) is not a function
Imported symbol incorrectly or module not properly registered (maybe missing `#`).
fixEnsure import is `import { mongoHandler } from '#mongodb-atlas-nuxt'` (note the hash). Error: Missing required configuration: publicApiKey, privateApiKey, groupId, clusterName
Configuration object 'mongodbAtlas' is missing from nuxt.config.ts or has missing keys.
fixAdd the required keys under `mongodbAtlas` in nuxt.config.ts as shown in the quickstart.
Error: EISDIR: illegal operation on a directory, read
Trying to use the module in a browser context; the handler should only run on the server.
fixMove the code to a server route or server plugin (e.g., `server/api/`).
Audit
Dependencies
nuxtrequiredRequires Nuxt 3 framework to auto-register module and provide `#mongodb-atlas-nuxt` alias