Introduction
MongoDB stores data as documents to keep information organized in a way that is easy to read and flexible to change.
Jump into concepts and practice - no test required
MongoDB stores data as documents to keep information organized in a way that is easy to read and flexible to change.
{ <field1>: <value1>, <field2>: <value2>, ... }{ "name": "Alice", "age": 30, "city": "New York" }{ "product": "Book", "price": 12.99, "inStock": true }{ "name": "Bob", "hobbies": ["reading", "hiking", "coding"] }This example inserts a document into the 'users' collection and then finds it by name.
db.users.insertOne({ "name": "John", "age": 25, "email": "john@example.com" });
db.users.find({ "name": "John" });Documents in MongoDB are stored in a format called BSON, which is like JSON but supports more data types.
Each document has a unique _id field automatically added if not provided.
MongoDB stores data as flexible documents with fields and values.
Documents are grouped in collections, making data easy to organize.
This format allows quick changes and storing complex data like arrays and nested objects.
name and value Alice?{ name: 'Bob', age: 30, hobbies: ['reading', 'swimming'] }, what is the value of the hobbies field?{ 'title': 'Book', pages: 250, author: 'John Doe' }