Skip to content

Instantly share code, notes, and snippets.

@aamedina
Created August 14, 2013 21:18
Show Gist options
  • Select an option

  • Save aamedina/6235741 to your computer and use it in GitHub Desktop.

Select an option

Save aamedina/6235741 to your computer and use it in GitHub Desktop.
(defn import!
[resources account-id]
(map
(fn [resource]
(if-let [doc (mc/find-by-id "resources" (:URI resource))]
(mc/update-by-id "resources" (:URI resource)
(if-let
[account (get-in doc ["accounts" account-id])]
{$inc {(str "accounts" "." account-id) 1}}
{$set {(str "accounts" "." account-id) 1}}))
(mc/insert "resources"
(merge resource {:_id (:URI resource)
:accounts (assoc {} account-id 1)}))))
resources))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment