Nuxt-mongodb: Nuxt 3 MongoDB Layer

MongoDB is a non-relational document database that provides support for JSON-like storage. The MongoDB database has a flexible data model that enables you to store unstructured data, and it provides full indexing support, and replication with rich and intuitive APIs.

Nuxt-mongodb is a Nuxt 3 plugin to use mongodb within your Nuxt 3 project

Nuxt 3 MongoDB Layer

A simple way to use mongoDB in your Nuxt 3 project.

Usage

Install the layer:

npm i -D nuxt-mongodb

Add the layer in the extends array in nuxt.config.ts:

export default defineNuxtConfig({
  extends: ["nuxt-mongodb"],
})

Add your mongo connection string and main database name in your .env file:

MONGO_CONNECTION_STRING=
MONGO_DB=

When you start your project, mongo will connect and you can use it anywhere, eg:

const db = mongo.db()
const response = await db.collection("YOUR_COLLECTION").find()