I have a bunch of documents, and I would like to build a three based on data from them. For example I have objects like this: [{ name: "1", category: "Paint", sub_category: "Inside", brand: "ACME" }, { name: "2", category: "Paint", sub_category: "Inside", brand: "ACME" }, { name: "asd", category: "Tools", sub_category: "Hammer", brand: "ACME" }, { name: "asd", category: "Tools", sub_category: "Hammer", brand: "UY" }, { name: "asd", category: "Paint", sub_category: "Outside", brand: "UY" }] And I would like to build a three like this: [ {category: "Paint", subs: ["Inside", "Outside"], brands: ["ACME", "UY"] }, { category: "Tools", subs:["Hammer"], brands: ["ACME", "UY"] }] Is it possible to build in inside couch? Or Move it to middleware?