0
0
MongoDBquery~30 mins

How MongoDB stores data as documents - Try It Yourself

Choose your learning style9 modes available
Understanding How MongoDB Stores Data as Documents
📖 Scenario: You are working on a small library system that keeps track of books. Each book has a title, author, and year of publication. You want to store this information in MongoDB, which saves data as documents.
🎯 Goal: Build a simple MongoDB document that represents a book with its details. Learn how to create and structure documents in MongoDB.
📋 What You'll Learn
Create a MongoDB document for a book with exact fields and values
Add a field to the document to specify the genre of the book
Use a MongoDB query to insert the document into a collection
Add a final field to the document to mark if the book is available
💡 Why This Matters
🌍 Real World
MongoDB is often used to store flexible data like user profiles, product catalogs, or content management data where each item can have different fields.
💼 Career
Understanding how to create and manipulate documents in MongoDB is essential for backend developers, data engineers, and anyone working with NoSQL databases.
Progress0 / 4 steps
1
Create the initial book document
Create a MongoDB document called book with these exact fields and values: title set to "The Great Gatsby", author set to "F. Scott Fitzgerald", and year set to 1925.
MongoDB
Need a hint?

Use curly braces {} to create a document and separate fields with commas.

2
Add a genre field to the book document
Add a new field called genre to the book document and set its value to "Classic".
MongoDB
Need a hint?

Add the new field inside the curly braces with a comma after the previous field.

3
Insert the book document into the collection
Use the MongoDB command db.books.insertOne(book) to insert the book document into the books collection.
MongoDB
Need a hint?

Use db.collectionName.insertOne(document) to add a document to a collection.

4
Add availability status to the book document
Add a new field called available to the book document and set its value to true to indicate the book is available.
MongoDB
Need a hint?

Boolean values in MongoDB documents are written as true or false without quotes.