This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-07
Channels
- # announcements (27)
- # babashka (29)
- # beginners (280)
- # calva (34)
- # cider (4)
- # circleci (11)
- # cljfx (10)
- # cljsrn (1)
- # clojure (526)
- # clojure-dev (9)
- # clojure-europe (42)
- # clojure-finland (5)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-taiwan (2)
- # clojure-uk (14)
- # clojurescript (40)
- # clr (43)
- # community-development (5)
- # css (4)
- # cursive (7)
- # duct (82)
- # events (1)
- # fulcro (72)
- # garden (44)
- # hoplon (3)
- # java (40)
- # jobs (4)
- # juxt (1)
- # luminus (53)
- # meander (13)
- # off-topic (26)
- # pathom (14)
- # pedestal (3)
- # portal (2)
- # rdf (3)
- # re-frame (54)
- # releases (10)
- # remote-jobs (3)
- # sci (74)
- # shadow-cljs (47)
- # startup-in-a-month (5)
- # testing (9)
- # tools-deps (73)
- # vim (12)
I can’t create a user from the default function provided by luminus
I’m getting the error:
java.lang.ClassCastException: mount.core.DerefableState cannot be cast to com.mongodb.DB
what do you mean?
I start the repl and make the request
how to fix this
where?
that gives:
Execution error (IllegalArgumentException) at com.mongodb.ConnectionString/<init> (ConnectionString.java:223). The connection string is invalid. Connection strings must start with ‘mongodb://’ u
ok, so the problem here is that you probably need to configure the mongo connection environment variable
I put the string in directly
and removed the env stuff
no, add a key called :database-url
and the value is the connection string to your mongodb database
that won’t change the error
This is my db.core, structured in a way to not need dev-config.edn (ns humboiserver.db.core (:require [monger.core :as mg] [monger.collection :as mc] [monger.operators :refer :all] [mount.core :refer [defstate]] [humboiserver.config :refer [env]])) #_(defstate db* :start (-> env :database-url mg/connect-via-uri) :stop (-> db* :conn mg/disconnect)) (defstate db* :start (-> “<mongodb+srv://username>:<mailto:[email protected]|[email protected]>/<dbname>?retryWrites=true&w=majority” mg/connect-via-uri) :stop (-> db* :conn mg/disconnect)) (defstate db :start (:db db*)) (defn create-user [user] (mc/insert db “users” user)) (defn update-user [id first-name last-name email] (mc/update db “users” {:_id id} {$set {:first_name first-name :last_name last-name :email email}})) (defn get-user [id] (mc/find-one-as-map db “users” {:_id id}))
where is dev-config.edn anyway?
Ok, so, there are a few problems here. First, the protocol of your db connection uri should be mongodb://
and not "mongodb+srv://
dbname is the name of the database
that’s literally the name
try connecting directly with that uri: (mg/connect-via-uri "
that’s exactly what I’m doing
I'm not really familiar with mongodb, never used it, but by the error message it seems your driver doesn't recognize the protocol
how to diagonse and fix this error?
now while making the request I’m getting this error:
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=http://cluster0.ww5gh.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: http://cluster0.ww5gh.mongodb.net}, caused by {http://java.net.UnknownHostException: http://cluster0.ww5gh.mongodb.net}}]
Ok, so, good news, you're not alone: https://github.com/michaelklishin/monger/issues/193
that’s my issue
raised some while back
also getting this error in the repl
2021-01-07 09:18:04,553 [cluster-clusterid{value=‘5ff6836934880e8a23671182’, description=‘null’}-http://cluster0.ww5gh.mongodb.net:27017] debug org.mongodb.driver.connection - closing connection connectionid{localvalue:131}
log not error
Maybe someone here more knowledgeable about the difference between mongodb:// and mongodb+srv://
using 3.4 string got rid of the error
Here a stackoverflow issue related to yours: https://stackoverflow.com/questions/50916467/how-to-connect-to-atlas-m0-free-tier-cluster-correctly-via-java-driver
I wonder if there's any way to find out which mongo driver version your app is picking up from the classpath
@guswill do you code react native?