 
 (ns dataloader.core
   (:require [monger.core :as mg])
-  (:use [monger.collection :only [insert]])
+  (:require [monger.collection :as coll])
   (:import [com.mongodb MongoOptions ServerAddress]
            [org.bson.types ObjectId])
   (:gen-class))

  (def residx (System/getenv "_ENV_BEL_RESIDX"))

  (if (nil? host)
    (println "no _ENV_MONGO_HOST is set"))
  (if (nil? db)
    (println "no _ENV_MONGO_DB is set"))
  (if (nil? residx)
    (println "no _ENV_BEL_RESIDX is set"))
  (if (nil? (or host db residx))
    (System/exit 1))


  ; connect to MongoDB and set the database
  (mg/connect! { :host host })
  (mg/set-db! (mg/get-db db))
  (outln "okay")
  (out "Dropping namespaces... ")
  (coll/drop "namespaces")
  (outln "okay")
  (doseq [x (namespace-urls residx)]
    (out (str x "... "))
    (download-ns x "temp.belns")
    (coll/insert "namespaces" (parse-namespace "temp.belns"))
    (outln "okay"))
  (mg/disconnect!))
