luminus

zendevil 2021-01-07T03:20:40.082Z

I can’t create a user from the default function provided by luminus

zendevil 2021-01-07T03:20:45.082300Z

I’m getting the error:

zendevil 2021-01-07T03:20:51.082500Z

java.lang.ClassCastException: mount.core.DerefableState cannot be cast to com.mongodb.DB

GusWill 2021-01-07T03:33:09.082900Z

@ps did you start mount?

zendevil 2021-01-07T03:33:23.083200Z

what do you mean?

zendevil 2021-01-07T03:33:45.083800Z

I start the repl and make the request

GusWill 2021-01-07T03:34:03.084400Z

That error usually means a mount-referenced var hasn't been started yet

zendevil 2021-01-07T03:34:11.084800Z

how to fix this

GusWill 2021-01-07T03:34:17.085Z

try running (mount/start)

zendevil 2021-01-07T03:34:24.085400Z

where?

GusWill 2021-01-07T03:34:28.085600Z

in your repl

zendevil 2021-01-07T03:35:01.085900Z

that gives:

zendevil 2021-01-07T03:35:02.086100Z

Execution error (IllegalArgumentException) at com.mongodb.ConnectionString/<init> (ConnectionString.java:223). The connection string is invalid. Connection strings must start with ‘mongodb://’ u

GusWill 2021-01-07T03:35:30.086700Z

ok, so the problem here is that you probably need to configure the mongo connection environment variable

GusWill 2021-01-07T03:35:52.087100Z

I think it's in dev-config.edn

GusWill 2021-01-07T03:36:34.087600Z

You have to provide a database-url

zendevil 2021-01-07T03:36:34.087700Z

I put the string in directly

zendevil 2021-01-07T03:36:54.088200Z

and removed the env stuff

GusWill 2021-01-07T03:37:04.088700Z

no, add a key called :database-url and the value is the connection string to your mongodb database

zendevil 2021-01-07T03:37:15.089Z

that won’t change the error

GusWill 2021-01-07T03:37:34.089400Z

can you paste your dev-config.edn here so that I can take a look?

zendevil 2021-01-07T03:39:37.090200Z

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}))

zendevil 2021-01-07T03:40:16.090600Z

where is dev-config.edn anyway?

GusWill 2021-01-07T03:42:04.092100Z

Ok, so, there are a few problems here. First, the protocol of your db connection uri should be mongodb:// and not "mongodb+srv://

GusWill 2021-01-07T03:42:36.092700Z

second, you need to provide an actual db name instead of &lt;dbname&gt;

zendevil 2021-01-07T03:43:03.093400Z

dbname is the name of the database

zendevil 2021-01-07T03:43:12.093600Z

that’s literally the name

GusWill 2021-01-07T03:43:26.094Z

ok

GusWill 2021-01-07T03:43:54.094600Z

try connecting directly with that uri: (mg/connect-via-uri "<mongodb+srv://username>:<mailto:password@cluster0.ww5gh.mongodb.net|password@cluster0.ww5gh.mongodb.net>/&lt;dbname&gt;?retryWrites=true&amp;w=majority")

zendevil 2021-01-07T03:44:32.095200Z

that’s exactly what I’m doing

GusWill 2021-01-07T03:44:57.095700Z

I'm not really familiar with mongodb, never used it, but by the error message it seems your driver doesn't recognize the protocol

GusWill 2021-01-07T03:45:29.096200Z

sorry, I meant (mg/connect-via-url "mongodb://...

GusWill 2021-01-07T03:45:57.096700Z

let me check the source, hold on

zendevil 2021-01-07T03:45:59.096800Z

how to diagonse and fix this error?

zendevil 2021-01-07T03:46:37.097300Z

now while making the request I’m getting this error:

zendevil 2021-01-07T03:46:37.097600Z

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}}]

GusWill 2021-01-07T03:46:42.097700Z

Ok, so, good news, you're not alone: https://github.com/michaelklishin/monger/issues/193

zendevil 2021-01-07T03:47:05.098Z

that’s my issue

zendevil 2021-01-07T03:47:10.098200Z

raised some while back

GusWill 2021-01-07T03:48:15.098800Z

Oh, you openned that issue?

zendevil 2021-01-07T03:48:24.099Z

also getting this error in the repl

zendevil 2021-01-07T03:48:25.099200Z

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}

zendevil 2021-01-07T03:48:37.099500Z

log not error

GusWill 2021-01-07T03:49:13.099900Z

Sorry, I can't help you there, I've never used Mongo.

GusWill 2021-01-07T03:49:45.100600Z

Maybe someone here more knowledgeable about the difference between mongodb:// and mongodb+srv://

GusWill 2021-01-07T03:50:27.101Z

@ps There's a #mongo channel, maybe try asking there?

zendevil 2021-01-07T03:55:22.101300Z

using 3.4 string got rid of the error

GusWill 2021-01-07T03:58:08.101700Z

Great. Maybe open an issue and report your findings?

GusWill 2021-01-07T03:58:27.102Z

Might help someone down the road

GusWill 2021-01-07T04:00:27.102300Z

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

GusWill 2021-01-07T04:01:37.103100Z

I wonder if there's any way to find out which mongo driver version your app is picking up from the classpath

zendevil 2021-01-07T04:05:36.103400Z

@guswill do you code react native?

GusWill 2021-01-07T04:13:07.103600Z

Not really. I worked on a RN project a long time ago (~2016-2017), so I'm sure its a different beast in 2021.