16 Commits
v1.0.4 ... main

Author SHA1 Message Date
37b5e425c4 Update package.json
Some checks failed
studio-nuxt-build / build-and-deploy (18, ubuntu-latest) (push) Has been cancelled
2025-01-20 19:13:58 +00:00
32deb047c5 Update package.json
Some checks are pending
studio-nuxt-build / build-and-deploy (18, ubuntu-latest) (push) Waiting to run
2025-01-20 18:51:38 +00:00
4036c56010 feat: disable autoconnect (#69) 2024-12-14 13:53:39 -07:00
c62ae2e134 docs: enhance Documentation (#70)
* docs: improve configuration and usage examples for

- Added a section for quick setup using  without additional configuration.
- Highlighted the importance of specifying  to connect to existing collections.
- Updated  examples with simplified schemas.

* Update README.md
2024-12-10 09:51:33 -07:00
eb7ad636dc chore(release): v1.0.6 2024-05-13 11:36:35 -06:00
ffb1eb43c7 chore: update readme 2024-04-24 15:44:38 -06:00
f504c6b79a chore: move docs 2024-04-24 15:34:39 -06:00
6b4d1ed0ae feat: add discriminator helper (#47)
* add discriminator.ts helper

Allow extension and inheritance of base models with discriminator models.

* Update index.ts

* fix typo in index.ts
2024-04-24 15:23:47 -06:00
3ef0d69ded fix: continue module setup process Without MONGODB_URI (#54) 2024-04-11 15:46:54 -06:00
edcf10eea1 docs: use new nuxi module add command in installation (#53) 2024-04-03 13:35:49 -06:00
89d50bd977 chore: update readme with documentation redirection 2024-02-26 10:11:45 -07:00
30407511a4 docs: fix examples list 2024-02-18 13:48:49 -07:00
0abeb6b265 docs: update examples 2024-02-18 13:48:28 -07:00
d746f451dd chore(release): v1.0.5 2024-02-01 08:25:28 -07:00
5a7936aac4 fix: replace consola with logger 2024-01-30 08:50:40 -07:00
64a4fa5383 chore(release): v1.0.4 2024-01-17 16:51:24 -07:00
36 changed files with 186 additions and 9063 deletions

View File

@ -1,6 +1,84 @@
# Changelog
## v1.0.6
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.4...v1.1.0)
### 🚀 Enhancements
- Add discriminator helper ([#47](https://github.com/arashsheyda/nuxt-mongoose/pull/47))
### 🩹 Fixes
- Replace consola with logger ([5a7936a](https://github.com/arashsheyda/nuxt-mongoose/commit/5a7936a))
- Continue module setup process Without MONGODB_URI ([#54](https://github.com/arashsheyda/nuxt-mongoose/pull/54))
### 📖 Documentation
- Update examples ([0abeb6b](https://github.com/arashsheyda/nuxt-mongoose/commit/0abeb6b))
- Fix examples list ([3040751](https://github.com/arashsheyda/nuxt-mongoose/commit/3040751))
- Use new `nuxi module add` command in installation ([#53](https://github.com/arashsheyda/nuxt-mongoose/pull/53))
### 🏡 Chore
- **release:** V1.0.4 ([64a4fa5](https://github.com/arashsheyda/nuxt-mongoose/commit/64a4fa5))
- **release:** V1.0.5 ([d746f45](https://github.com/arashsheyda/nuxt-mongoose/commit/d746f45))
- Update readme with documentation redirection ([89d50bd](https://github.com/arashsheyda/nuxt-mongoose/commit/89d50bd))
- Move docs ([f504c6b](https://github.com/arashsheyda/nuxt-mongoose/commit/f504c6b))
- Update readme ([ffb1eb4](https://github.com/arashsheyda/nuxt-mongoose/commit/ffb1eb4))
### ❤️ Contributors
- Arash ([@arashsheyda](http://github.com/arashsheyda))
- Justin Bellero <jpbellero@gmail.com>
- Roryc ([@Coiggahou2002](http://github.com/Coiggahou2002))
- Daniel Roe ([@danielroe](http://github.com/danielroe))
## v1.0.5
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.4...v1.0.5)
### 🩹 Fixes
- Replace consola with logger ([5a7936a](https://github.com/arashsheyda/nuxt-mongoose/commit/5a7936a))
### 🏡 Chore
- **release:** V1.0.4 ([64a4fa5](https://github.com/arashsheyda/nuxt-mongoose/commit/64a4fa5))
### ❤️ Contributors
- Arash <arashi.sheyda@gmail.com>
## v1.0.4
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.3...v1.0.5)
### 💅 Refactors
- Split services into individual files ([d6b8e91](https://github.com/arashsheyda/nuxt-mongoose/commit/d6b8e91))
### 📖 Documentation
- Update dependencies ([12d62d8](https://github.com/arashsheyda/nuxt-mongoose/commit/12d62d8))
- Update dependencies ([7183742](https://github.com/arashsheyda/nuxt-mongoose/commit/7183742))
### 🏡 Chore
- Test bundler module resolution ([#36](https://github.com/arashsheyda/nuxt-mongoose/pull/36))
- Update dependencies ([#38](https://github.com/arashsheyda/nuxt-mongoose/pull/38))
- Update dependencies ([bdab2c5](https://github.com/arashsheyda/nuxt-mongoose/commit/bdab2c5))
- Update playground ([42b3b83](https://github.com/arashsheyda/nuxt-mongoose/commit/42b3b83))
- Update cover ([61cc323](https://github.com/arashsheyda/nuxt-mongoose/commit/61cc323))
- Update cover ([bf7f9db](https://github.com/arashsheyda/nuxt-mongoose/commit/bf7f9db))
### ❤️ Contributors
- Arash
- Amir H. Moayeri
- Daniel Roe <daniel@roe.dev>
## v1.0.3
[compare changes](https://github.com/arashsheyda/nuxt-mongoose/compare/v1.0.2...v1.0.3)

View File

@ -1,4 +1,4 @@
![nuxt-mongoose](https://raw.githubusercontent.com/arashsheyda/nuxt-mongoose/main/docs/public/cover.jpg)
![nuxt-mongoose](https://docs.arashsheyda.me/modules/nuxt-mongoose.jpg)
<div align="center">
<h1>Nuxt Mongoose</h1>
@ -10,7 +10,7 @@
## Installation
```bash
pnpm add nuxt-mongoose
npx nuxi@latest module add nuxt-mongoose
```
## Usage
@ -29,7 +29,7 @@ export default defineNuxtConfig({
### Configuration
You can configure the module by adding a `mongoose` section to your `nuxt.config` file.
You can configure the module by adding a `mongoose` section to your `nuxt.config` file:
```ts
export default defineNuxtConfig({
@ -41,9 +41,26 @@ export default defineNuxtConfig({
})
```
by default, `nuxt-mongoose` will auto-import your schemas from the `models` directory from `server` directory. You can change this behavior by setting the `modelsDir` option.
By default, `nuxt-mongoose` will auto-import your schemas from the `models` directory in the `server` directory. You can change this behavior by setting the `modelsDir` option.
---
#### 🛠️ **Quick Setup Without Configuration**
If you prefer to use the default configuration, skip adding the `mongoose` section to your `nuxt.config.ts` file. Simply provide your MongoDB connection URI in a `.env` file like this:
```env
MONGODB_URI="mongodb+srv://username:password@cluster0.mongodb.net/<database-name>?retryWrites=true&w=majority"
```
> 🔹 Replace `username`, `password`, and `<database name>` with your MongoDB credentials and database name.
That's it! The module will automatically use the `MONGODB_URI` and default settings for your connection. No additional configuration is required.
---
*For more details about connection options, check out the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options).*
* for more information about the options, please refer to the [Mongoose documentation](https://mongoosejs.com/docs/connections.html#options). *
## API
@ -86,6 +103,40 @@ export const User = defineMongooseModel({
})
```
#### Connecting to an Existing Collection
If you need to connect to an **existing collection** in the database, you must specify the collection name using the `options` field. Otherwise, Mongoose will create a new collection based on the model name.
```ts
import { defineMongooseModel } from '#nuxt/mongoose'
export const ProductSchema = defineMongooseModel({
name: 'Product',
schema: {
name: { type: String, required: true },
price: { type: Number, required: true },
stock: { type: Number, default: 0 },
},
options: {
collection: 'products_collection', // Ensure it uses the correct collection name
},
})
```
---
#### Important Notes
- Using the `options.collection` field ensures that the model interacts with the specified collection (`products_collection` in the example above).
- Without this option, a new collection will be created using the pluralized version of the model name (e.g., `Products`).
### Configuration
For detailed [configuration](https://docs.arashsheyda.me/nuxt-mongoose/getting-started/configuration) and usage instructions, please refer to our [documentation](https://docs.arashsheyda.me/nuxt-mongoose).
## License
[MIT License](./LICENSE)

12
docs/.gitignore vendored
View File

@ -1,12 +0,0 @@
node_modules
*.iml
.idea
*.log*
.nuxt
.vscode
.DS_Store
coverage
dist
sw.*
.env
.output

View File

@ -1,2 +0,0 @@
shamefully-hoist=true
strict-peer-dependencies=false

1
docs/README.md Normal file
View File

@ -0,0 +1 @@
# the docs has been moved to [arashsheyda/docs](https://github.com/arashsheyda/docs/tree/main/content/1.nuxt-mongoose)

View File

@ -1,36 +0,0 @@
export default defineAppConfig({
docus: {
title: 'Nuxt Mongoose',
description: 'A Nuxt module for simplifying the use of Mongoose in your project.',
image: '/cover.jpg',
socials: {
twitter: 'arash_sheyda',
github: 'arashsheyda/nuxt-mongoose',
},
github: {
dir: 'docs/content',
branch: 'main',
repo: 'nuxt-mongoose',
owner: 'arashsheyda',
edit: true,
},
aside: {
level: 1,
collapsed: false,
exclude: [],
},
header: {
logo: true,
showLinkIcon: true,
exclude: [],
},
footer: {
iconLinks: [
{
href: 'https://nuxt.com',
icon: 'simple-icons:nuxtdotjs',
},
],
},
},
})

View File

@ -1,295 +0,0 @@
<template>
<svg
width="403"
height="226"
viewBox="0 0 403 226"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<g clip-path="url(#clip0_1180_138)">
<g opacity="0.54">
<path
d="M0 12C0 5.37259 5.37258 0 12 0H391C397.627 0 403 5.37258 403 12V214C403 220.627 397.627 226 391 226H12C5.37259 226 0 220.627 0 214V12Z"
fill="url(#paint0_linear_1180_138)"
fill-opacity="0.3"
/>
<path
d="M12 0.5H391C397.351 0.5 402.5 5.64873 402.5 12V214C402.5 220.351 397.351 225.5 391 225.5H12C5.64873 225.5 0.5 220.351 0.5 214V12C0.5 5.64873 5.64873 0.5 12 0.5Z"
stroke="url(#paint1_linear_1180_138)"
stroke-opacity="0.4"
/>
</g>
<path
opacity="0.54"
d="M49.7811 28H57.5876C57.8356 28 58.0792 27.9354 58.2939 27.8125C58.5086 27.6896 58.6869 27.5128 58.8108 27.3C58.9347 27.0871 58.9999 26.8457 58.9998 26.5999C58.9997 26.3542 58.9343 26.1128 58.8102 25.9001L53.5676 16.9001C53.4437 16.6873 53.2654 16.5105 53.0507 16.3877C52.836 16.2648 52.5925 16.2001 52.3446 16.2001C52.0967 16.2001 51.8532 16.2648 51.6385 16.3877C51.4238 16.5105 51.2455 16.6873 51.1216 16.9001L49.7811 19.2028L47.1602 14.6998C47.0361 14.487 46.8578 14.3104 46.6431 14.1875C46.4283 14.0647 46.1847 14 45.9368 14C45.6889 14 45.4453 14.0647 45.2305 14.1875C45.0158 14.3104 44.8375 14.487 44.7134 14.6998L38.1896 25.9001C38.0655 26.1128 38.0001 26.3542 38 26.5999C37.9999 26.8457 38.0651 27.0871 38.189 27.3C38.3129 27.5128 38.4912 27.6896 38.7059 27.8125C38.9207 27.9354 39.1643 28 39.4122 28H44.3125C46.254 28 47.6859 27.1547 48.6711 25.5057L51.063 21.4001L52.3442 19.2028L56.1893 25.8028H51.063L49.7811 28ZM44.2326 25.8005L40.8128 25.7998L45.9391 17.0004L48.4969 21.4001L46.7843 24.3407C46.13 25.4107 45.3867 25.8005 44.2326 25.8005Z"
fill="white"
fill-opacity="0.1"
/>
<line
opacity="0.54"
x1="43.5"
y1="75.5"
x2="84.5"
y2="75.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="43.5"
y1="147.5"
x2="63.5"
y2="147.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="172.5"
y1="147.5"
x2="192.899"
y2="147.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="301.5"
y1="147.5"
x2="321.5"
y2="147.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="143.5"
y1="20.5"
x2="167.5"
y2="20.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="184.5"
y1="20.5"
x2="208.5"
y2="20.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="225.5"
y1="20.5"
x2="249.5"
y2="20.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="43.5"
y1="93.5"
x2="178.5"
y2="93.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="43.5"
y1="162.5"
x2="115.544"
y2="162.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="172.5"
y1="162.5"
x2="244.5"
y2="162.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="301.5"
y1="162.5"
x2="373.5"
y2="162.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="43.5"
y1="111.5"
x2="178.5"
y2="111.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="43.5"
y1="177.5"
x2="115.5"
y2="177.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="172.5"
y1="177.5"
x2="244.5"
y2="177.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<line
opacity="0.54"
x1="301.5"
y1="177.5"
x2="373.5"
y2="177.5"
stroke="white"
stroke-opacity="0.1"
stroke-width="5"
stroke-linecap="round"
/>
<rect
opacity="0.54"
x="335.465"
y="17.619"
width="41.1089"
height="11.7454"
rx="2.93635"
fill="white"
fill-opacity="0.1"
/>
<rect
opacity="0.54"
x="212"
y="70"
width="164"
height="44"
rx="5"
fill="url(#paint2_linear_1180_138)"
fill-opacity="0.1"
/>
<!-- Mongo Logo -->
<g transform="translate(170, 80) scale(2)">
<rect width="32" height="32" rx="7.5" style="fill:#023430" />
<path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50" />
<path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2" />
<path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f" />
</g>
</g>
<defs>
<filter
id="filter0_d_1180_138"
x="162.895"
y="74.8947"
width="76.2105"
height="76.2105"
filterUnits="userSpaceOnUse"
color-interpolation-filters="sRGB"
>
<feFlood flood-opacity="0" result="BackgroundImageFix" />
<feColorMatrix
in="SourceAlpha"
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"
result="hardAlpha"
/>
<feOffset dy="4" />
<feGaussianBlur stdDeviation="2" />
<feComposite in2="hardAlpha" operator="out" />
<feColorMatrix
type="matrix"
values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.44 0"
/>
<feBlend
mode="normal"
in2="BackgroundImageFix"
result="effect1_dropShadow_1180_138"
/>
<feBlend
mode="normal"
in="SourceGraphic"
in2="effect1_dropShadow_1180_138"
result="shape"
/>
</filter>
<linearGradient
id="paint0_linear_1180_138"
x1="201.5"
y1="0"
x2="201.5"
y2="102.822"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="white" />
<stop offset="1" stop-color="white" stop-opacity="0" />
</linearGradient>
<linearGradient
id="paint1_linear_1180_138"
x1="201.5"
y1="-1.34109e-07"
x2="201.527"
y2="153.598"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="white" />
<stop offset="1" stop-color="white" stop-opacity="0" />
</linearGradient>
<linearGradient
id="paint2_linear_1180_138"
x1="294"
y1="70"
x2="294"
y2="114"
gradientUnits="userSpaceOnUse"
>
<stop stop-color="white" />
<stop offset="1" stop-color="white" stop-opacity="0" />
</linearGradient>
<clipPath id="clip0_1180_138">
<rect width="403" height="226" fill="white" />
</clipPath>
</defs>
</svg>
</template>

View File

@ -1,18 +0,0 @@
<template>
<svg id="NuxtMongooseLogo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235.5 33.2">
<rect width="32" height="32" rx="7.5" style="fill:#023430" />
<path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50" />
<path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2" />
<path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f" />
<text transform="translate(32.8 25.6)" style="font-size:25.818214416503906px;font-family:var(--font-sans);font-weight:700">
<tspan fill="currentColor" x="4" y="0">Nuxt</tspan>
<tspan x="67.8" y="0" style="fill:#10aa50">Mongoose</tspan>
</text>
</svg>
</template>
<style>
.NuxtMongooseLogo {
font-family: serif;
}
</style>

View File

@ -1,78 +0,0 @@
---
title: Home
navigation: false
layout: page
main:
fluid: false
---
:ellipsis{right=0px width=75% blur=150px}
::block-hero
---
cta:
- Get started
- /docs/getting-started/setup
secondary:
- Open on GitHub →
- https://github.com/arashsheyda/nuxt-mongoose
---
#title
Nuxt [Mongoose]{style="color: var(--color-primary-500)"}
#description
A Nuxt module for simplifying the use of [Mongoose](https://mongoosejs.com/) in your project.
#support
:illustration
::
::card-grid
#title
<h1 class="center">Elevate Your <br/> <span class=highlight> Developer Experience</span></h1>
#root
:ellipsis{left=15rem width=40rem top=10rem blur=140px}
#default
::card{icon=tabler:code}
#title
Nuxt DevTools Support
#description
Dive into your database with confidence. Benefit from Nuxt Devtools support, allowing you to inspect and debug your DB operations seamlessly.
::
::card{icon=tabler:cloud-bolt}
#title
Auto Connection
#description
Forget about manual connection hassles. This module seamlessly handles the connection to your Mongoose database, making setup a breeze.
::
::card{icon=tabler:plug}
#title
Extendable & hackable
#description
This module grants you access to the full spectrum of Mongoose functionalities. Leverage the power of Mongoose in your project.
::
::
<style>
.highlight {
color: var(--color-primary-500);
}
.center {
text-align: center;
}
.card svg {
height: 3rem!important;
width: 3rem!important;
}
.support {
display: flex;
justify-content: center;
}
</style>

View File

@ -1,56 +0,0 @@
# Setup
A Nuxt module for simplifying the use of Mongoose in your project.
## Installation
1. Install `nuxt-mongoose` to your dependencies.
::code-group
```bash [pnpm]
pnpm add nuxt-mongoose -D
```
```bash [npm]
npm install nuxt-mongoose -D
```
```bash [yarn]
yarn add nuxt-mongoose -D
```
::
2. Add `nuxt-mongoose` to the `modules` section of your `nuxt.config` file.
```ts [nuxt.config]
export default defineNuxtConfig({
modules: [
'nuxt-mongoose',
],
})
```
::alert{ type=success }
That's it! You can now use Mongoose in your Nuxt app ✨
::
## Options
You can configure the module by adding a `mongoose` section to your `nuxt.config` file.
read more about [Mongoose options](/docs/getting-started/configuration).
```ts [nuxt.config]
export default defineNuxtConfig({
mongoose: {
// Options
},
})
```
If you want to configure only the `uri` just add `MONGODB_URI` in your `.env` file.
```env
MONGODB_URI=YOUR_MONGO_URI
```

View File

@ -1,21 +0,0 @@
# Configuration
Configure Nuxt Mongoose with the `mongoose` property.
```ts [nuxt.config]
export default defineNuxtConfig({
mongoose: {
uri: 'process.env.MONGODB_URI',
options: {},
modelsDir: 'models',
devtools: true,
},
})
```
| **Key** | **Type** | **Default** | **Description** |
| ---------------------------- | ---------- | ----------------------- | ---------------------------------------------------------------------------------------------------- |
| `uri` | `string` | process.env.MONGODB_URI | Connection Uri String |
| `options` | `ConnectOptions` | { } | Connection Options |
| `modelsDir` | `string` | models | The models(schema) directory located in `server` for auto-import |
| `devtools` | `boolean` | true | Enable Mongoose module in [`Nuxt Devtools`](https://github.com/nuxt/devtools) |

View File

@ -1,2 +0,0 @@
icon: tabler:brand-mongodb
navigation.redirect: /getting-started/setup

View File

@ -1,74 +0,0 @@
# Utils
Discover all available utils.
## `defineMongooseModel`
This function creates a new Mongoose model with schema. Example usage:
::code-group
```ts [named parameters]
export const User = defineMongooseModel({
name: 'User',
schema: {
email: {
type: 'string',
required: true,
unique: true,
},
},
options: {
},
hooks(schema) {
},
})
```
```ts [positional parameters]
import { defineMongooseModel } from '#nuxt/mongoose'
export const User = defineMongooseModel('User', {
email: {
type: 'string',
required: true,
unique: true,
},
}, {
}, (schema) => {
})
```
::
| **Key** | **Type** | **Require** | **Description** |
| ---------------------------- | ----------- | ----------- | ----- |
| `name` | `string` | true | Name of Model |
| `schema` | [`SchemaDefinition`](https://mongoosejs.com/docs/schematypes.html) | true | Schema Definition of Model |
| `options` | [`SchemaOptions`](https://mongoosejs.com/docs/guide.html#options) | false | Schema Options for Model |
| `hooks` | [`(schema: Schema<T>) => void`](https://mongoosejs.com/docs/middleware.html) | false | Schema Hooks Function to customize Model |
::alert
you can access the default connection with importing it from mongoose:
::
```
import { connection } from 'mongoose'
```
## `defineMongooseConnection`
This function creates a new Mongoose connection.
- `nuxt-mongoose` provides a default connection for you, it auto-register a plugin in nitro, so you don't need to use this function unless you want to create a new connection. more info [here](https://github.com/arashsheyda/nuxt-mongoose/blob/main/src/runtime/server/plugins/mongoose.db.ts).
Example usage:
```ts
import { defineMongooseConnection } from '#nuxt/mongoose'
export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')
```

View File

@ -1,8 +0,0 @@
# Devtools (beta)
`nuxt-mongoose` comes with a [Nuxt Devtools](https://github.com/nuxt/devtools) module that allows you to manage your collections and generate api-endpoints & schemas...
Here is a demo video:
:video-player{src="https://www.youtube.com/watch?v=hK0npSfr_Vs"}

View File

@ -1,5 +0,0 @@
# Examples
Here are a few examples:
- Nuxt Mongoose Minimal: [:icon{name="tabler:brand-github"} Github](https://github.com/arashsheyda/nuxt-mongoose-minimal) [:icon{name="tabler:world"} Website](https://nuxt-mongoose-minimal.vercel.app/)

View File

@ -1,2 +0,0 @@
title: API
icon: tabler:book

View File

@ -1 +0,0 @@
icon: tabler:file-description

View File

@ -1,5 +0,0 @@
# Playground
:ellipsis{right=0px width=75% blur=150px}
:sandbox{src="https://stackblitz.com/github/arashsheyda/nuxt-mongoose-minimal"}

View File

@ -1 +0,0 @@
icon: tabler:play-volleyball

View File

@ -1,3 +0,0 @@
title: Releases
icon: tabler:clipboard-text
navigation.redirect: https://github.com/arashsheyda/nuxt-mongoose/releases

View File

@ -1,19 +0,0 @@
export default defineNuxtConfig({
extends: '@nuxt-themes/docus',
app: {
head: {
link: [
{
rel: 'icon',
type: 'image/x-icon',
href: '/mongoose-icon.svg',
},
],
},
},
modules: [
'@nuxthq/studio',
],
})

View File

@ -1,17 +0,0 @@
{
"name": "nuxt-mongoose-docs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate",
"preview": "nuxi preview",
"lint": "eslint ."
},
"devDependencies": {
"@nuxt-themes/docus": "^1.15.0",
"@nuxthq/studio": "^1.0.8",
"nuxt": "^3.9.3"
}
}

8363
docs/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB

View File

@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><g fill="none"><rect width="256" height="256" fill="#023430" rx="60"/><path fill="#10AA50" d="M171.173 107.591c-10.537-46.481-32.497-58.855-38.099-67.602A99.398 99.398 0 0 1 126.949 28c-.296 4.13-.84 6.73-4.35 9.862c-7.047 6.283-36.977 30.673-39.496 83.486c-2.347 49.242 36.2 79.605 41.292 82.744c3.916 1.927 8.685.041 11.012-1.728c18.581-12.752 43.969-46.75 35.786-94.773"/><path fill="#B8C4C2" d="M128.545 177.871c-.97 12.188-1.665 19.27-4.129 26.235c0 0 1.617 11.603 2.753 23.894h4.019a223.446 223.446 0 0 1 4.384-25.732c-5.203-2.56-6.827-13.702-7.027-24.397Z"/><path fill="#12924F" d="M135.565 202.275c-5.258-2.429-6.779-13.806-7.013-24.404a499.824 499.824 0 0 0 1.136-52.545c-.276-9.194.13-85.158-2.265-96.28a92.425 92.425 0 0 0 5.651 10.936c5.602 8.754 27.569 21.128 38.099 67.609c8.203 47.941-17.047 81.849-35.608 94.684Z"/></g></svg>

Before

Width:  |  Height:  |  Size: 926 B

View File

@ -1 +0,0 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 235.5 33.2"><rect width="32" height="32" rx="7.5" style="fill:#023430"/><path d="M21.4,13.4C20.1,7.6,17.3,6.1,16.6,5a10.1,10.1,0,0,1-.7-1.5,1.6,1.6,0,0,1-.6,1.2,14.1,14.1,0,0,0-4.9,10.5c-.3,6.1,4.5,9.9,5.1,10.3a1.4,1.4,0,0,0,1.4-.2,12.1,12.1,0,0,0,4.5-11.9" style="fill:#10aa50"/><path d="M16.1,22.2a17.8,17.8,0,0,1-.5,3.3s.2,1.5.3,3h.5a30.6,30.6,0,0,1,.5-3.2C16.3,25,16.1,23.6,16.1,22.2Z" style="fill:#b8c4c2"/><path d="M16.9,25.3c-.6-.3-.8-1.7-.8-3.1s.2-4.3.1-6.5,0-10.7-.3-12.1L16.6,5c.7,1.1,3.5,2.6,4.8,8.4A12,12,0,0,1,16.9,25.3Z" style="fill:#12924f"/><text transform="translate(32.8 25.6)" style="font-size:25.818214416503906px;font-family:OpenSans-Bold, Open Sans;font-weight:700">Nuxt <tspan x="70.8" y="0" style="fill:#10aa50">Mongoose</tspan></text></svg>

Before

Width:  |  Height:  |  Size: 851 B

View File

@ -1,8 +0,0 @@
{
"extends": [
"@nuxtjs"
],
"lockFileMaintenance": {
"enabled": true
}
}

View File

@ -1,18 +0,0 @@
import { defineTheme } from 'pinceau'
export default defineTheme({
color: {
primary: {
50: '#e8f5e9',
100: '#c8e6c9',
200: '#a5d6a7',
300: '#81c784',
400: '#66bb6a',
500: '#10a74f',
600: '#10a74f',
700: '#388e3c',
800: '#2e7d32',
900: '#1b5e20',
},
},
})

View File

@ -1,3 +0,0 @@
{
"extends": "./.nuxt/tsconfig.json"
}

View File

@ -1,13 +1,13 @@
{
"name": "nuxt-mongoose",
"type": "module",
"version": "1.0.3",
"version": "1.0.6",
"private": false,
"packageManager": "pnpm@8.7.4",
"description": "Nuxt 3 module for MongoDB with Mongoose",
"license": "MIT",
"funding": "https://github.com/sponsors/arashsheyda",
"homepage": "https://nuxt-mongoose.nuxt.space",
"homepage": "https://docs.arashsheyda.me/nuxt-mongoose",
"repository": {
"type": "git",
"url": "git+https://github.com/arashsheyda/nuxt-mongoose"
@ -39,6 +39,7 @@
"dist"
],
"scripts": {
"prepare": "npm run build",
"build": "nuxt-module-build && npm run build:client",
"build:client": "nuxi generate client",
"dev": "nuxi dev playground",
@ -49,8 +50,8 @@
"lint": "eslint . --fix"
},
"dependencies": {
"@nuxt/devtools-kit": "1.0.8",
"@nuxt/devtools-ui-kit": "1.0.8",
"@nuxt/devtools-kit": "^1.3.9",
"@nuxt/devtools-ui-kit": "^1.3.9",
"@nuxt/kit": "^3.9.3",
"@vueuse/core": "^10.7.2",
"defu": "^6.1.4",

View File

@ -70,7 +70,6 @@ export default defineNuxtModule<ModuleOptions>({
if (!options.uri) {
logger.warn('Missing MongoDB URI. You can set it in your `nuxt.config` or in your `.env` as `MONGODB_URI`')
return
}
const { resolve } = createResolver(import.meta.url)

View File

@ -1,11 +1,17 @@
import mongoose from 'mongoose'
import type { DevtoolsServerContext, ServerFunctions } from '../types'
import { logger } from '@nuxt/kit'
import { setupDatabaseRPC } from './database'
import { setupResourceRPC } from './resource'
export function setupRPC(ctx: DevtoolsServerContext): ServerFunctions {
mongoose.connect(ctx.options.uri, ctx.options.options)
if (!ctx.options.uri) {
ctx.options.uri = ''
logger.warn('MongoDB autoconnect is disabled, configure `uri` to enable.')
} else {
mongoose.connect(ctx.options.uri, ctx.options.options)
}
return {
getOptions() {

View File

@ -1,5 +1,6 @@
import type { ConnectOptions } from 'mongoose'
import { logger } from '@nuxt/kit'
import { consola } from 'consola'
import { colors } from 'consola/utils'
import mongoose from 'mongoose'
// @ts-ignore
@ -8,13 +9,14 @@ import { useRuntimeConfig } from '#imports'
export async function defineMongooseConnection({ uri, options }: { uri?: string; options?: ConnectOptions } = {}): Promise<void> {
const config = useRuntimeConfig().mongoose
const mongooseUri = uri || config.uri
if (!(mongooseUri as string).trim()) return
const mongooseOptions = options || config.options
try {
await mongoose.connect(mongooseUri, { ...mongooseOptions })
logger.success('Connected to `MongoDB`')
consola.success('Connected to MongoDB')
}
catch (err) {
logger.error('Error connecting to `MongoDB`', err)
consola.error(colors.red(`Error connecting to MongoDB: ${err}`))
}
}

View File

@ -0,0 +1,33 @@
import type { Model, SchemaDefinition, SchemaOptions } from 'mongoose'
import mongoose from 'mongoose'
export function defineMongooseDiscriminatorModel<T>(
nameOrOptions: string | {
name: string;
baseModel: Model<T>;
schema: SchemaDefinition<T>;
options?: SchemaOptions;
hooks?: (schema: mongoose.Schema<T>) => void;
},
baseModel?: Model<T>,
schema?: SchemaDefinition<T>,
options?: SchemaOptions,
hooks?: (schema: mongoose.Schema<T>) => void,
): Model<T> {
let name: string
if (typeof nameOrOptions === 'string') { name = nameOrOptions }
else {
name = nameOrOptions.name
baseModel = nameOrOptions.baseModel
schema = nameOrOptions.schema
options = nameOrOptions.options
hooks = nameOrOptions.hooks
}
const newSchema = new mongoose.Schema<T>(schema, options as any)
if (hooks)
hooks(newSchema)
return baseModel!.discriminator<T>(name, newSchema)
}

View File

@ -1,2 +1,3 @@
export { defineMongooseConnection } from './connection'
export { defineMongooseModel } from './model'
export { defineMongooseDiscriminatorModel } from './discriminator'