MongoDB Connection Diagram Using Monger

I am new to clojure.

Are there any idioms / patterns around connecting with a mongodb through a friend?

I need to connect and disconnect using

(monger.core/connect) & (monger.core/disconnect conn)

respectively. everytime?

Is there a way to reuse a connection from a connection pool?

+4
source share
2 answers

monger uses MongoClient, which joins the connection pool. After that, connectyou can continue to work with this pool until you are done, and then disconnect. See the monger documentation for supported connection parameters (for example, the maximum number of connections in the pool, 10 by default).

+6
source

, ? let, :

(ns pipegen.core
    (:require [monger.core :as mg]
              [monger.collection :as mc]))

(def conn (atom (mg/connect-via-uri mongo-uri)))
(mc/insert (:db @conn) "collectionname" {:name "methuzula" :age 123})

, , mg/connect-via-uri, , - :

{:conn #object[com.mongodb.MongoClient]
 :db   #object[com.mongodb.DB]}

def, .


, , , , :

dbs. , , , , ! http://software-ninja-ninja.blogspot.co.il/2014/04/5-faces-of-dependency-injection-in.html

, clojurians on slack - , , clojure, em out! https://clojurians.slack.com/

+2

Source: https://habr.com/ru/post/1542583/


All Articles