Error: "No such namespace: mc" (monger, monger.collection)

I’m running into a namespace error. When I attempt to query a collection from the cljblog.db namespace.

cljblog/db.clj:


(ns cljblog.db
  (:require [monger.core :as mg]
            [monger.collection :as mc]))

(def db (-> "mongodb://127.0.0.1/cljblog-test"
            mg/connect-via-uri
            :db))

Steps taken:

  1. start repl
    lein repl

  2. switch namespace

(in-ns 'cljblog.db)

  1. Query the collection

(mc/find-maps db "articles")

Full error message:

 Syntax error compiling at (form-init17588852473615642213.clj:1:1).
No such namespace: mc 

My project.clj

(defproject cljblog "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.10.0"]
                 [compojure "1.6.1"]
                 [ring/ring-defaults "0.3.2"]
                 [com.novemberain/monger "3.1.0"]]
  :plugins [[lein-ring "0.12.5"]]
  :ring {:handler cljblog.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.2"]]}})

The repl was restarted after the addition of each dependency.
I get the same error with the latest monger version (3.5.0)

mongodb is installed and running on the system.

in-ns doesn’t load the namespace, it just changes the current namespace. So that ns form with all its contents, along with all the defs and whatnot in that namespace - it’s all ignored.

One way to fix it would be to add (require 'cljblog.db) before that call to in-ns. The other way would be to figure out how to properly load files in Lein REPL. I don’t use Lein myself so I don’t know.

1 Like