Skip to content

Commit

Permalink
feat: 🎨 provide useMongoClient
Browse files Browse the repository at this point in the history
function to retrieve the mongo client
  • Loading branch information
Morgbn committed Jun 2, 2023
1 parent d627e6a commit f0aa080
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineNuxtModule<ModuleOptions>({
})
nuxt.options.nitro.imports.presets.push({
from: resolve('runtime/server/helpers/db'),
imports: ['useDb', 'useCol', 'useObjectId']
imports: ['useMongoClient', 'useDb', 'useCol', 'useObjectId']
})

// Add doc routes
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/server/helpers/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ client.connect()
const dbName = new URL(dbUrl ?? '').pathname.split('/').pop() ?? 'test'
const db = client.db(dbName)

export function useMongoClient () { return client }

export function useDb (name?: string): Db {
return client.db(name ?? dbName)
}
Expand Down

0 comments on commit f0aa080

Please sign in to comment.