Registry / database / mongodb-atlas-nuxt

mongodb-atlas-nuxt

JSON →
library1.2.7jsnpmunverified

A Nuxt module for interacting with MongoDB Atlas API from Cloudflare Workers. Version 1.2.7 uses `#mongodb-atlas-nuxt` import alias and provides a handler with methods like insertMany, findOne, etc. Released on npm, actively maintained. Key differentiator: Nuxt-first integration with Cloudflare, auto-imports a mongoHandler that returns a scoped client for a specific database and collection, reducing boilerplate. Requires Nuxt 3 and a MongoDB Atlas API key.

npm install mongodb-atlas-nuxt
INSTALL
IMPORT
SIG · MONGODB-ATLAS-NUXT
M
mongodb-atlas-nuxt
databasejavascriptv1.2.7
harness data pending
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 }; });
Debug
Known issues
gotchaThe database name in mongoHandler must not include the cluster name; it refers to the database within the cluster.
fix
Use the database name (e.g., 'myDatabase') not the cluster name.
affects: ALL
gotchaThe query object for findOne uses `$oid` notation for ObjectId. Using plain string or `new ObjectId()` will fail.
fix
Use `{ _id: { $oid: '...' } }` format as shown in the README.
affects: ALL
gotchaThe module requires Nuxt 3 and may not work with Nuxt 2 or other frameworks.
fix
Ensure your project is using Nuxt 3 with `npx nuxi init`.
affects: ALL
gotchaThe import alias `#mongodb-atlas-nuxt` only works in server-side code (like server/api/) after the module is properly configured in nuxt.config.
fix
Place handler calls in server routes or plugins, not in client code.
affects: ALL
gotchaAtlas API keys must have appropriate permissions (Project Data Access Read/Write) to perform operations.
fix
Create an API key in Atlas with necessary roles and use that in config.
affects: ALL
Errors
Common errors & fixes
Cannot find module '#mongodb-atlas-nuxt'
The module is not installed or not added to `modules` in nuxt.config.ts.
fix
Run `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 `#`).
fix
Ensure 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.
fix
Add 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.
fix
Move the code to a server route or server plugin (e.g., `server/api/`).
Upgrade
Version history
1.2.7latest on npm
Audit
Dependencies
nuxtrequiredRequires Nuxt 3 framework to auto-register module and provide `#mongodb-atlas-nuxt` alias
Agent activity
13 hits · last 30 days
node
12
Resources
mongodb-atlas-nuxt — npm install mongodb-atlas-nuxt · libregistry