             [monger.core :as m]
             [monger.collection :as mc]
             [monger.joda-time]
-            [monger.operators :refer :all])
+            [monger.operators :refer :all]
+            [monger.conversion :refer :all])
   (:import [org.bson.types ObjectId]
            [com.mongodb DB WriteConcern]))
 

    (str id)))

(defn add-item! [basket-id item]
  (let [id (ObjectId. basket-id)]
    (mc/insert "items" (merge {:_id id :_basket (ObjectId. basket-id)} item))
    (str id)))

(defn delete-basket! [id]
  (mc/remove "basket" {:_id (ObjectId. id)}))

  (m/set-db! (m/get-db))) ;; db name is in the uri

(defn load-basket [id]
  (let [basket-id (to-object-id id)]
    (assoc (mc/find-map-by-id "basket" basket-id)
      :items (mc/find-maps "items" {:_basket basket-id}))))

