Open kamran-12 opened 8 months ago
hey @kamran-12
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.
let me know if you any other question
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 configurationnuxt-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
I have not used this plugin yet but I am planning to. My questions:
models.ts
, then put it directly intoserver
folder, in place ofmodels
folder, will it work? Will it need any non-default configurations?defineMongooseConnection
anddefineMongooseModel
methods inreadme.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 themfrom '#nuxt/mongoose'
will be enough?export const connection = defineMongooseConnection('mongodb://127.0.0.1/nuxt-mongoose')