Ch 3 · MongoDB Introduction and Setup · MongoDB

Topic 3 of 3 in MongoDB — Complete Tutorial (Beginner) — 4 lessons.

What is MongoDB?

Get started with MongoDB: understand document databases and perform basic operations. Rather than storing rows in fixed tables, MongoDB keeps flexible JSON-like documents inside collections, and every document gets its own unique _id. That suits data where records vary, such as articles with and without images. You will connect to a database, add a document and read it back.

MongoDB in Code

This is a complete, minimal MongoDB program. Follow each step in order: create a MongoClient for a local server, connect, choose the myapp database and its users collection, insert a user with insertOne, and fetch it with findOne. Notice that every call is awaited and the connection is closed at the end, two habits worth building now.

Practice: What is MongoDB?

Write your first MongoDB script from the starter code. You will connect to a local server, pick a database and collection, insert a document with a name, age and email, then find it and print it before closing the connection. A correct answer awaits every step and prints the stored document, including the _id that MongoDB added.

Solution & Challenge: What is MongoDB?

Compare your script with the worked solution, which stores Bob in a people collection and prints him back. The challenge then covers the full cycle: insert three users with insertMany, list them all with find and toArray, change one user's age with updateOne, remove another with deleteOne, and finally show the two users that remain.

All topics in MongoDB Beginner

  1. MongoDB Atlas and Cloud Deployment
  2. MongoDB CRUD Operations
  3. MongoDB Introduction and Setup