From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Message model and form state

Message model and form state

So now we're going to work on the messages. And we're going to be saving messages in the database in a collection. So I think the first thing that we should do is create a new model for messages. So let's go to Models, create a new file called message.js. And then from here, we're going to bring in schema. We're going to do this just like we did with the other models. So schema, model, models. And that's going to be from, whoops, I don't want const here. We want import. So we want to import from mongoose. And then let's create our schema. So const, we'll call this message schema. And that's going to be set to a new schema. And then we pass in an object that has all of the fields. So here's the fields that we're going to have. So we're going to have a few object ID fields that are related to another table. So for instance, we're going to have a sender of the message. And the sender is going to be, obviously, the user that sends the message, that sends that form that's on the property…

Contents