SyntaxStudy
Sign Up
MongoDB Beginner 8 min read

Introduction to MongoDB

MongoDB is a document-oriented NoSQL database. Unlike relational databases that store data in tables and rows, MongoDB stores data as JSON-like documents called BSON (Binary JSON). This makes it flexible and scalable for modern applications.

MongoDB is schema-less, meaning each document in a collection can have different fields.

Example
// MongoDB document example
{
  "_id": ObjectId("5f43a0b6b31b28a9c2a4b5c1"),
  "name": "Alice Johnson",
  "email": "alice@example.com",
  "age": 29,
  "skills": ["JavaScript", "Python", "MongoDB"],
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "country": "USA"
  },
  "createdAt": ISODate("2024-01-15T10:30:00Z")
}

// MongoDB Shell Commands
// Start MongoDB shell: mongosh
// Show databases
show dbs

// Use/create database
use myapp

// Show collections
show collections