Example 1 — Employees and orders collections
db.employees.drop()
db.orders.drop()
db.active_employees.drop()
db.sales_by_region.drop()
db.employee_directory.drop()
db.employees.insertMany([
{ name: "Alice Chen", dept: "Engineering", status: "active", salary: 95000, startDate: ISODate("2022-03-15") },
{ name: "Bob Martinez", dept: "Sales", status: "active", salary: 72000, startDate: ISODate("2021-08-01") },
{ name: "Carol Wu", dept: "Engineering", status: "inactive", salary: 88000, startDate: ISODate("2020-11-20") },
{ name: "Dan Patel", dept: "Support", status: "active", salary: 65000, startDate: ISODate("2023-01-10") },
{ name: "Eve Johnson", dept: "Sales", status: "active", salary: 78000, startDate: ISODate("2022-06-30") }
])
db.orders.insertMany([
{ region: "North", product: "Widget Pro", amount: 299, status: "completed" },
{ region: "South", product: "Widget Lite", amount: 99, status: "completed" },
{ region: "North", product: "Desk Lamp", amount: 65, status: "completed" },
{ region: "East", product: "Office Chair",amount: 450, status: "completed" },
{ region: "West", product: "USB Hub", amount: 45, status: "pending" },
{ region: "South", product: "Widget Pro", amount: 299, status: "completed" }
])
db.employees.createIndex({ status: 1 })
db.orders.createIndex({ status: 1, region: 1 }) How It Works
Five employees (one inactive) and six orders across four regions. Target collections start empty—they will be populated by $out examples below.

