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
@ps did you start mount?
what do you mean?
I start the repl and make the request
That error usually means a mount-referenced var hasn't been started yet
how to fix this
try running (mount/start)
where?
in your repl
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 think it's in dev-config.edn
You have to provide a database-url
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
can you paste your dev-config.edn here so that I can take a look?
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:password@cluster0.ww5gh.mongodb.net|password@cluster0.ww5gh.mongodb.net>/<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://
second, you need to provide an actual db name instead of <dbname>
dbname is the name of the database
that’s literally the name
ok
try connecting directly with that uri: (mg/connect-via-uri "<mongodb+srv://username>:<mailto:password@cluster0.ww5gh.mongodb.net|password@cluster0.ww5gh.mongodb.net>/<dbname>?retryWrites=true&w=majority")
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
sorry, I meant (mg/connect-via-url "mongodb://...
let me check the source, hold on
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
Oh, you openned that issue?
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
Sorry, I can't help you there, I've never used Mongo.
Maybe someone here more knowledgeable about the difference between mongodb:// and mongodb+srv://
@ps There's a #mongo channel, maybe try asking there?
using 3.4 string got rid of the error
Great. Maybe open an issue and report your findings?
Might help someone down the road
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?
Not really. I worked on a RN project a long time ago (~2016-2017), so I'm sure its a different beast in 2021.