Fork me on GitHub
#luminus
<
2021-01-07
>
zendevil.eth03:01:40

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

zendevil.eth03:01:45

I’m getting the error:

zendevil.eth03:01:51

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

GusWill03:01:09

@ps did you start mount?

zendevil.eth03:01:23

what do you mean?

zendevil.eth03:01:45

I start the repl and make the request

GusWill03:01:03

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

zendevil.eth03:01:11

how to fix this

GusWill03:01:17

try running (mount/start)

GusWill03:01:28

in your repl

zendevil.eth03:01:02

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

GusWill03:01:30

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

GusWill03:01:52

I think it's in dev-config.edn

GusWill03:01:34

You have to provide a database-url

zendevil.eth03:01:34

I put the string in directly

zendevil.eth03:01:54

and removed the env stuff

GusWill03:01:04

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

zendevil.eth03:01:15

that won’t change the error

GusWill03:01:34

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

zendevil.eth03:01:37

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

zendevil.eth03:01:16

where is dev-config.edn anyway?

GusWill03:01:04

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

GusWill03:01:36

second, you need to provide an actual db name instead of <dbname>

zendevil.eth03:01:03

dbname is the name of the database

zendevil.eth03:01:12

that’s literally the name

GusWill03:01:54

try connecting directly with that uri: (mg/connect-via-uri ":/<dbname>?retryWrites=true&w=majority")

zendevil.eth03:01:32

that’s exactly what I’m doing

GusWill03:01:57

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

GusWill03:01:29

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

GusWill03:01:57

let me check the source, hold on

zendevil.eth03:01:59

how to diagonse and fix this error?

zendevil.eth03:01:37

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

zendevil.eth03:01:37

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

zendevil.eth03:01:05

that’s my issue

zendevil.eth03:01:10

raised some while back

GusWill03:01:15

Oh, you openned that issue?

zendevil.eth03:01:24

also getting this error in the repl

zendevil.eth03:01:25

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}

GusWill03:01:13

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

GusWill03:01:45

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

GusWill03:01:27

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

zendevil.eth03:01:22

using 3.4 string got rid of the error

GusWill03:01:08

Great. Maybe open an issue and report your findings?

GusWill03:01:27

Might help someone down the road

GusWill04:01:37

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

zendevil.eth04:01:36

@guswill do you code react native?

GusWill04:01:07

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