How to save data in mongodb using server actions in nextjs 13
Please follow below steps to save data in mongo db using server actions
- Create page with form
- Add action prop and pass the function to be called when the form is submitted
- Write an async function using 'use server' directive
- You can write a logic to save form data into mongodb in above function
async function save(data) {
"use server";
await saveToMongoDB({ data });
}
Published on: Jun 06, 2023, 01:05 AM