monger

When using monger, do I need to supply connection each request?

六月ゝ 毕业季﹏ 提交于 2020-01-03 00:02:49
问题 In the documentation, the mongodb connection is established once, before being used without passing the connection to each command, is that the proper way to use monger, or should I pass the database connection to each call? 回答1: If you work with single database then it's best to set the connection once: (mg/connect! db-spec) But it's not a good idea when you have multiple databases. Monger have with-connection macro (see API docs) for this case: (mg/with-connection db-connection ...) You may

Clojure: Aggregate and Count in Maps

浪子不回头ぞ 提交于 2019-12-12 13:37:18
问题 I guess this question qualifies as an entry-level clojure problem. I basically have troubles processing a clojure map multiple times and extract different kinds of data. Given a map like this, I'm trying to count entries based on multiple nested keys: [ { "a": "X", "b": "M", "c": 188 }, { "a": "Y", "b": "M", "c": 165 }, { "a": "Y", "b": "M", "c": 313 }, { "a": "Y", "b": "P", "c": 188 } ] First, I want to group the entries by the a-key values: { "X" : [ { "b": "M", "c": 188 } ], "Y" : [ { "b":

When using monger, do I need to supply connection each request?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 16:41:00
In the documentation , the mongodb connection is established once, before being used without passing the connection to each command, is that the proper way to use monger, or should I pass the database connection to each call? If you work with single database then it's best to set the connection once: (mg/connect! db-spec) But it's not a good idea when you have multiple databases. Monger have with-connection macro ( see API docs ) for this case: (mg/with-connection db-connection ...) You may establish all connections once during the initialization of your app: (def conn1 (mg/connect db-spec))