首页 > 解决方案 > The connection string is invalid mongo db

问题描述

I am using monger to connect with the database, but I'm getting that the connection string is invalid:

Caused by: java.lang.IllegalArgumentException: The connection string is invalid. Connection strings must start with 'mongodb://'

Here's my code in which I'm putting the connection string:

(let [{:keys [conn db]} (mg/connect-via-uri "mongodb+srv://username:pass@cluster0-ww5gh.mongodb.net/test?retryWrites=true&w=majority")
      fs (mg/get-gridfs conn "test")]
  (defn store-file [{:keys [file filename format content-type]}]
    (gfs/store-file (gfs/make-input-file fs file)
                    (gfs/filename filename)
                    (gfs/metadata {:format format})
                    (gfs/content-type content-type)))

  (defn gfs-find-by-id [id]
    (gfs/find-by-id fs id))
  (defn find-file [id] (gfs/find-by-id fs id))

  (defn find-one [coll query] (mc/find-one-as-map db coll query))

  (defn find-by-id [coll id] (mc/find-map-by-id db coll id))

  (defn find [coll query] (mc/find-maps db coll query))

  (defn insert [coll query] (mc/insert-and-return db coll query))

  (defn update [coll entry query] (mc/update db coll entry query {:upsert true}))
  (defn update-multi [coll entry query] (mc/update db coll entry query {:upsert true :multi true}))
  (defn update-by-id [coll id query] (mc/update-by-id db coll id query {:upsert true}))

  (defn find-page-n [coll query page n]
    (prn "finding" n "items on page " page)
    (q/with-collection
      db
      coll
      (q/find query)
      (q/paginate :page page :per-page n))))


How to fix this error?

标签: mongodbclojuremonger

解决方案


mongodb+srvMongoDB 3.6 引入了连接字符串,它也允许“协议”。如果您的实例是此版本或更高版本,则必须将您的monger依赖项更新为当前版本。否则mongodb用于协议(如错误消息所示)。


推荐阅读