Hey all π! Next.js is an amazing full-stack framework and MongoDB is a great NoSQL database. Using them together will make an app super fast and awesome! In this post, we'll go ahead and set up the Mongoose ODM inside our Next.js app to make use of ...
blog.usmans.me6 min read
Won't it take time for the server to first connect to the Mongodb server and then fetch data.
Is there any way by which we are connected to the Mongodb server forever and when request will be sent to it. It just has to fetch the data and return to the nextjs server function.
This worked for me
```import { Schema, model, models } from "mongoose";
const UserSchema = new Schema({ displayName: { type: String, required: true }, email: { type: String, required: true, unique: true }, phone: { type: String, unique: true }, password: { type: String }, pro: { type: Boolean, default: false }, author: { type: Boolean, default: false }, photoURL: { type: String }, }); console.log(model); // undefined console.log(models.UserModel); //this solved const User = models.UserModel;
export default User;
```
Server Error TypeError: (0 , mongooseWEBPACK_IMPORTED_MODULE_0.model) is not a function
This error happened while generating the page. Any console logs will be displayed in the terminal window. --error above-- --code below--
import { Schema, model, models } from "mongoose";
const UserSchema = new Schema({ displayName: { type: String, required: true }, email: { type: String, required: true, unique: true }, phone: { type: String, unique: true }, password: { type: String }, pro: { type: Boolean, default: false }, author: { type: Boolean, default: false }, photoURL: { type: String }, }); const User = models.User || model("User", UserSchema);
export default User;
Suen
Thank you.