Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick questions #46

Open
kamran-12 opened this issue Feb 18, 2024 · 2 comments
Open

Quick questions #46

kamran-12 opened this issue Feb 18, 2024 · 2 comments

Comments

@kamran-12
Copy link

I have not used this plugin yet but I am planning to. My questions:

  1. If I put all my models into a single file and name it models.ts, then put it directly into server folder, in place of models folder, will it work? Will it need any non-default configurations?
  2. I noticed defineMongooseConnection and defineMongooseModel methods in readme.md but cannot find them in Mongoose documentation. Why? Are these exclusive to nuxt-mongoose? If so, what about regular Mongoose functionality? Do I need something else to import to access them or importing them from '#nuxt/mongoose' will be enough?
  3. In which folder/file do I put the following code?
import { defineMongooseConnection } from '#nuxt/mongoose'

export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')
@arashsheyda
Copy link
Owner

arashsheyda commented Feb 18, 2024

hey @kamran-12

  • yes you can define all your models in one file and you'll be able to use it.
  • you don't need to define another connection (defineMongooseConnection) as nuxt-mongoose auto define it for you, you just need to pass your connections url. check configuration

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.

  • defineMongooseModel is like a shortcut, it create a new schema and return a model. it has all the functionalities of a normal mongoose model. learn more about defineMongooseModel

let me know if you any other question

@kamran-12
Copy link
Author

kamran-12 commented Feb 19, 2024

hey @kamran-12

  • yes you can define all your models in one file and you'll be able to use it.
  • you don't need to define another connection (defineMongooseConnection) as nuxt-mongoose auto define it for you, you just need to pass your connections url. check configuration

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.

  • defineMongooseModel is like a shortcut, it create a new schema and return a model. it has all the functionalities of a normal mongoose model. learn more about defineMongooseModel

let me know if you any other question

@arashsheyda Thanks, I would like to see an actual project using your plugin for better understanding. I don't have any questions other than those I asked in the original post, but I feel they were not completely answered. In the question number 2, what I am asking is, does your library contain all Mongoose functionality or if I need, say, Mongoose.Schema, schema.index, schema.virtual, do I need to import them separately from the regular Mongoose library? Other parts will be clear to me when I see an actual project, it will be hard to understand otherwise.

Edit: I found this: https://nuxt-mongoose.nuxt.space/docs/api/examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants