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 - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Message model and form state12m 59s
-
(Locked)
Message submit and API route14m 22s
-
(Locked)
Require auth for contact form3m 53s
-
(Locked)
Fetch messages10m 30s
-
(Locked)
Display messages11m 15s
-
(Locked)
Mark as read15m 19s
-
(Locked)
Delete messages8m 38s
-
(Locked)
Order new first3m 25s
-
(Locked)
New message count display11m 5s
-
(Locked)
Global context for unread messages11m 6s
-
(Locked)
-