Closed R0N1n-dev closed 1 year ago
hey. There is nothing wrong with your setup, as you can see in the server-routes from devtools, it's returning an empty array, just make sure you have a record in your collection.
if you are sure that you have some records and still nothing is showing up, can you share a minimal reproduction of your project? thanks
@R0N1n-dev and also you can auto-import your models. the default folder for auto-import is ~/server/models
and you can change it from your nuxt-config
, an example would be like:
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
'nuxt-mongoose',
],
mongoose: {
uri: 'mongodb://127.0.0.1:27017/nuxt-mongoose',
modelsDir: '../models', //here we are setting the modelsDir to `~/models`
},
})
~
is your project's root directorymodelsDir
auto-import is ~/server/
Ok, thats fixed but now i have no idea on how to add data coz my code is not working. https://stackblitz.com/github/R0N1n-dev/nuxt-mongoose. i get an error on post request
@R0N1n-dev it's not related to this module, if you want to use insertOne
in mongoose, you either need to write it like GameSchema.collection.insertOne
or you can simply use GameSchema.create
aslo I encourage you to use typescript :) mongoose supports typescript and it will help you to solve things faster
.ts
you can see it's telling you, and you can benefit from it auto-complete feature.method
(e.g. .post
) as suffix to your api name, it will auto check for the req method so you dont need to write event.node.req.method === "POST"
Thank you
No problem, feel free to ask any other question if you have, just DM me on twitter
Will do. I love mongodb and so this plugin will really help. Good day
Have installed the package and followed instructions but cant display data. The dev tools query show no response. Whats going on coz i Have no errors but clearly am not getting any data from my database. What is the right way to do this coz the documentation is scant