SyntaxStudy
Sign Up
MongoDB Beginner 1 min read

What is MongoDB?

MongoDB is a document-oriented NoSQL database that stores data as BSON (Binary JSON) documents instead of rows in tables. Each document is a self-contained unit that can hold nested objects and arrays, making it ideal for hierarchical or schema-flexible data. MongoDB was first released in 2009 and has become one of the most popular databases in the world for web applications, real-time analytics, and content management systems. Its horizontal scaling model, called sharding, allows it to handle enormous data volumes across distributed clusters. Unlike relational databases, MongoDB does not require a fixed schema, which means different documents in the same collection can have entirely different fields. This flexibility accelerates development because the data model can evolve without costly migrations.
Example
// Start the MongoDB shell (mongosh)
mongosh

// Show all databases
show dbs

// Switch to (or create) a database
use myAppDB

// Show all collections in the current database
show collections

// A sample BSON document (stored internally as binary JSON)
{
  "_id": ObjectId("64a1f2b3c4d5e6f7a8b9c0d1"),
  "name": "Alice",
  "age": 30,
  "email": "alice@example.com",
  "address": {
    "city": "New York",
    "zip": "10001"
  },
  "hobbies": ["reading", "cycling"],
  "createdAt": ISODate("2024-01-15T08:30:00Z")
}

// Check server status
db.runCommand({ serverStatus: 1 })

// Drop a database (use with caution)
db.dropDatabase()