 (defn from-vertex
   ([label] (from-vertex label {}))
   ([label where]
-   [{:$group {:_id "$from" :to {:$first "$from"} :_history {:$addToSet "$_history"}}}
+   [;; {:$group {:_id "$from" :to {:$first "$from"} :_history {:$addToSet "$_history"}}}
     {:$lookup
      {:from label
       :localField "from"

(defn to-vertex
  ([label] (to-vertex label {}))
  ([label where]
   [{:$group {:_id "$to" :to {:$first "$to"} :_history {:$addToSet "$_history"}}}
    {:$lookup
     {:from label
      :localField "to"

(defn qount
  [label]
  [{:$count label}])

(defn dedup
  []
  [{:$group {:_id "$gid" :dedup {:$first "$$ROOT"}}}
   {:$replaceRoot {:newRoot "$dedup"}}])

(defn dedup-on
  [field]
  (let [dollar (str "$" (name field))]
    ;; {:$group {:_id dollar (keyword field) {:$first dollar} :_history {:$addToSet "$_history"}}}
    [{:$group {:_id dollar :dedup {:$first "$$ROOT"}}}
     {:$replaceRoot {:newRoot "$dedup"}}]))

(defn offset
  [n]
