CRUD Operations: Insert
🚀 Goal: Insert New Documents Like a Pro
Your platform is growing, and it’s time to expand your offerings! Imagine a host adding a brand-new property or a guest signing up for the first time. As the backend engineer, you’re the one who makes these moments possible—bringing new data to life in your MongoDB collection.
In this exercise, you’ll master the art of inserting documents. Every new listing, guest, or booking starts with a single insert—and your code is what makes it happen.
đź§© Exercise: Insert a Document
-
Open the File
Navigate toserver/src/lab/
and opencrud-5.lab.js
. -
Locate the Function
Find thecrudCreateItem
function in the file. -
Update the Code
- Insert the document stored in the
item
variable into the collection. - The
item
variable is already formatted and ready for insertion.
- Insert the document stored in the
🚦 Test Your API
- Go to
server/src/lab/rest-lab
directory. - Open
crud-5-lab.http
. - Click Send Request to execute the API call.
- Verify the response confirms successful insertion of the document.