---
title: "Comment by nandan vasista on \"🗃️ How to use Mongoose with Next.js for MongoDB?\" | Hashnode"
description: "This worked for me ```import { Schema, model, models } from &quot;mongoose&quot;; const UserSchema = new Schema({ displayName: { type: String, required: true },"
url: "https://hashnode.com/posts/how-to-use-mongoose-with-nextjs-for-mongodb/625bd39852fb7bd53380fbd2/comment/636151488dbe21712c7dc036"
---

[Discussion](https://hashnode.com/posts/how-to-use-mongoose-with-nextjs-for-mongodb/625bd39852fb7bd53380fbd2)

Comment [🗃️ How to use Mongoose with Next.js for MongoDB?](https://hashnode.com/posts/how-to-use-mongoose-with-nextjs-for-mongodb/625bd39852fb7bd53380fbd2)

[nandan vasista](https://hashnode.com/@nandan910)

[Nov 1, 2022](https://hashnode.com/posts/how-to-use-mongoose-with-nextjs-for-mongodb/625bd39852fb7bd53380fbd2/comment/636151488dbe21712c7dc036)

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;

\`\`\`
