mongodb - 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?
解决方案
mongodb+srv
MongoDB 3.6 引入了连接字符串,它也允许“协议”。如果您的实例是此版本或更高版本,则必须将您的monger
依赖项更新为当前版本。否则mongodb
用于协议(如错误消息所示)。
推荐阅读
- node.js - 无服务器框架:未找到无服务器错误功能:
- javascript - 在 FlatList(native) 上呈现数据的错误 - React Native
- java - 出现异常如何自动重启springboot应用
- laravel - 上传本地服务器 - 找不到类 'Illuminate\Support\Facades\Input'
- javascript - Javascript 和 Python 之间的差异
- linux - 在 Linux 中使用 grep 和 AWK 命令获取文件列表
- ubuntu - VSCode 调试器不使用递归函数
- java - jpa oneToMany和jackson序列化问题(新手)
- c++ - 如何在 C++ 中找到变量的最派生子类?
- android - 得到错误:忍者:错误复制文件构建停止:子命令失败