    (to-edge state where)
    (to-vertex state {})))
 
+(defn mark
+  [state label]
+  (let [path (str "_history." label)]
+    [{:$addFields {path "$$ROOT"}}
+     {:$project
+      {(str path "._history") false
+       (str path "._id") false}}]))
+
+(defn select
+  [state labels]
+  [{:$project
+    (reduce
+     (fn [project label]
+       (assoc project label (str "$_history." label)))
+     {} labels)}])
+
 (def steps
   {:where has
    :from-edge from-edge

   [cheshire.core :as json]
   [taoensso.timbre :as log]
   [ophion.mongo :as mongo]))

(defn outgoing
  [from label]
  [{:$match {:from from :label label}}
   {:$project {:gid true :from true :to true}}
   {:$lookup
    {:from "element"
     :localField "to"
     :foreignField "gid"
     :as "outgoing"}}
   {:$unwind "$outgoing"}
   {:$replaceRoot {:newRoot "$outgoing"}}
   {:$project {:_id false}}])

(defn has
  [state where]

      :localField "gid"
      :foreignField "from"
      :as "to"}}
    {:$project
     {:history "$_history"
      :to
      {:$filter
       {:input "$to"
        :as "o"
        :cond
        {:$eq ["$$o.label" label]}}}}}
    {:$unwind "$to"}
    {:$addFields {"to._history" "$history" "to.yellol" "1333"}}
    {:$replaceRoot {:newRoot "$to"}}]
   where))

