1- # DatabaseProvider
1+ # Database
22
3- DatabaseProvider is the central repository for MongoClient, databases, collections.
4- It is referenced by the @ref :[ MongoDAO] ( dao/index.md ) Patttern.
3+ Database Connection can be done using MongConfig.
54
6- ## MongoConfig
5+ DatabaseProvider Instance contains setup for registries and databases.
76
8- MongoConfig holds all the neded Data for creating a MongoClient .
9- It is used for DatabaseProvider creation .
7+ Database provider will ues database by name from MongoConfig by default .
8+ Multiple databases access is supported on the same client is supported. For different MongoDBs you have to use different providers .
109
11- | Key | Description | Default value |
12- | :---------------------| :--------------------------| :-------------------|
13- | database | default database to use | |
14- | host | | 127.0.0.1 |
15- | port | | 27017 |
16- | applicationName | | simple-mongo-app |
17- | userName | used for Authentification | |
18- | password | used for Authentification | |
19- | poolOptions | | MongoPoolOptions() |
20- | compressors | List: zlib, snappy, zstd | List() |
21- | customClientSettings | | None |
10+ ## DatabaseProvider
11+ DatabaseProvider is the central repository for MongoClient, registries, databases and collections.
2212
13+ Every @ref :[ MongoDAO] ( dao/index.md ) / @ref :[ GridFSDAO] ( gridfs/index.md ) Instance needs this class.
2314
24- ## MongoPoolOptions
15+ @ @ snip [ Mongo Conf ] ( /docs/src/main/scala/DatabaseProviderDoc.scala ) { #provider }
2516
26- | Key | Default value |
27- | :-------------------------------| :--------------|
28- | maxConnectionIdleTime | 60 |
29- | maxSize | 50 |
30- | minSize | 0 |
31- | DefaultMaintenanceInitialDelay | 0 |
3217
18+ ## Create MongoConfig with application.conf
3319
34- ## Create MongoConfig with properties
20+ ### With default path
3521
36- Example:
22+ Default path in application.conf: mongo
3723
38- ``` scala
39-
40- val config = MongoConfig (" my_database" , host = " localhost" ,
41- applicationName = " Awesome Application Name" )
24+ @@snip [ Mongo Conf] ( /docs/src/main/resources/docs.conf ) { #sample_config }
4225
43- ```
26+ Scala Code Snippet
4427
45- ## Create MongoConfig with config
28+ @ @ snip [ Mongo Conf ] ( /docs/src/main/scala/DatabaseProviderDoc.scala ) { #sample_config_from_path }
4629
47- Create application.conf:
30+ ### With custom path
4831
49- ``` hocon
32+ @ @ snip [ Mongo Conf ] ( /docs/src/main/resources/docs.conf ) { #sample_config_custom }
5033
51- config.test.auth.mongo {
52- database = "another_database"
53- host = "localhost"
54- port = 270007
55- applicationName = "simple-mongo-config-test-with-auth"
56- userName = "admin_user"
57- password = "1234"
58- pool {
59- minSize = 5
60- maxSize = 100
61- }
34+ Scala Code Snippet
6235
63- ```
36+ @ @ snip [ Mongo Conf ] ( /docs/src/main/scala/DatabaseProviderDoc.scala ) { #sample_config_from_custom_path }
6437
65- ``` scala
66- val config = MongoConfig .fromPath(" config.test.auth.mongo" )
67- ```
6838
6939## Create MongoConfig with custom ClientSettings
7040
@@ -76,7 +46,50 @@ val config = MongoConfig("my_database", customClientSettings = Some(myClientSett
7646
7747## Registries
7848
49+ @@@ note { title=ScalaDriverDocs }
50+
51+ Additional Info for [ Registries] ( https://mongodb.github.io/mongo-java-driver/4.0/driver-scala/getting-started/quick-start-case-class/#configuring-case-classes )
52+
53+ @@@
54+
55+ ### Create Case Classes
56+
57+ @@snip [ Mongo Conf] ( /docs/src/main/scala/DatabaseProviderDoc.scala ) { #provider_with_registry_classes }
58+
59+ ### Create Registry
60+
61+ @@snip [ Mongo Conf] ( /docs/src/main/scala/DatabaseProviderDoc.scala ) { #provider_with_registry }
62+
63+
64+ ## MongoConfig Options
65+
66+ MongoConfig holds all the neded Data for creating a MongoClient.
67+
68+ It is used for DatabaseProvider creation.
69+
70+ | Key | Description | Default value |
71+ | :---------------------| :--------------------------| :-------------------|
72+ | database | default database to use | |
73+ | host | | 127.0.0.1 |
74+ | port | | 27017 |
75+ | applicationName | | simple-mongo-app |
76+ | userName | used for Authentification | |
77+ | password | used for Authentification | |
78+ | poolOptions | | MongoPoolOptions() |
79+ | compressors | List: zlib, snappy, zstd | List() |
80+ | customClientSettings | | None |
81+
82+
83+ ## MongoConfig Pool Options
84+
85+ | Key | Default value |
86+ | :-------------------------------| :--------------|
87+ | maxConnectionIdleTime | 60 |
88+ | maxSize | 50 |
89+ | minSize | 0 |
90+ | DefaultMaintenanceInitialDelay | 0 |
7991
92+ ## Multiple databases access
8093
8194
8295
0 commit comments