         "else" "$$PRUNE"}}}
      {:$replaceRoot {:newRoot "$_root"}}]))
 
+(defn gather
+  [query-map]
+  (let [queries (into {} (map (fn [[k query]] [k (translate query)]) query-map))]
+    [{:$facet queries}]))
+
 (def steps
   {:fromEdge from-edge
    :toEdge to-edge

(defn from-vertex
  ([label] (from-vertex label {}))
  ([label where]
   [;; {:$group {:_id "$from" :to {:$first "$from"} :_history {:$addToSet "$_history"}}}
    {:$lookup
     {:from label
      :localField "from"
      :foreignField "gid"
      :as "vertex"}}
    {:$unwind "$vertex"}
    ;; {:$unwind "$_history"}
    {:$match where}
    {:$addFields {"vertex._history" "$_history"}}
    {:$replaceRoot {:newRoot "$vertex"}}]))

  ([field]
   (let [path (dollar field)]
     [{:$project {:_id false}}
      {:$group {:_id {field path "_history" "$_history"} :dedup {:$first "$$ROOT"}}}
      {:$replaceRoot {:newRoot "$dedup"}}])))

(defn where
  [where]
