Example 1 — Orders and articles collections
db.orders.drop()
db.articles.drop()
db.orders.insertMany([
{ orderId: "O-01", category: "electronics", status: "shipped", amount: 199 },
{ orderId: "O-02", category: "electronics", status: "shipped", amount: 89 },
{ orderId: "O-03", category: "books", status: "shipped", amount: 24 },
{ orderId: "O-04", category: "electronics", status: "pending", amount: 149 },
{ orderId: "O-05", category: "home", status: "shipped", amount: 55 },
{ orderId: "O-06", category: "books", status: "cancelled", amount: 18 },
{ orderId: "O-07", category: "electronics", status: "shipped", amount: 299 },
{ orderId: "O-08", category: "home", status: "pending", amount: 42 },
{ orderId: "O-09", category: "books", status: "shipped", amount: 32 },
{ orderId: "O-10", category: "electronics", status: "shipped", amount: 79 }
])
db.articles.insertMany([
{ title: "MongoDB Basics", tags: ["mongodb", "database", "tutorial"] },
{ title: "Node API Guide", tags: ["nodejs", "api", "tutorial"] },
{ title: "Aggregation Tips", tags: ["mongodb", "aggregation"] },
{ title: "React Hooks", tags: ["react", "frontend"] },
{ title: "Pipeline Patterns", tags: ["mongodb", "aggregation", "tutorial"] }
]) How It Works
Ten orders across three categories and five tagged articles—enough to show clear frequency rankings and tag counts after unwind.

