File tree Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Expand file tree Collapse file tree 4 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 9
9
<version >1.0-SNAPSHOT</version >
10
10
11
11
<properties >
12
- <maven-compiler-plugin .source>13 </maven-compiler-plugin .source>
13
- <maven-compiler-plugin .target>13 </maven-compiler-plugin .target>
12
+ <maven-compiler-plugin .source>8 </maven-compiler-plugin .source>
13
+ <maven-compiler-plugin .target>8 </maven-compiler-plugin .target>
14
14
<project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
15
- <project .reporting.outputEncoding>UTF-8</project .reporting.outputEncoding>
16
15
<mongodb-driver-sync .version>3.11.0</mongodb-driver-sync .version>
17
16
<maven-compiler-plugin .version>3.8.1</maven-compiler-plugin .version>
18
17
</properties >
Original file line number Diff line number Diff line change 6
6
import org .bson .Document ;
7
7
8
8
import java .util .ArrayList ;
9
+ import java .util .List ;
10
+ import java .util .ResourceBundle ;
9
11
import java .util .logging .Level ;
10
12
import java .util .logging .Logger ;
11
13
12
14
public class Connection {
13
15
14
- private static final String connectionString = "mongodb+srv://<USERNAME>:<PASSWORD>@cluster0-abcde.mongodb.net/test?w=majority" ;
16
+ private final static ResourceBundle PROPERTIES = ResourceBundle . getBundle ( "application" ) ;
15
17
16
18
public static void main (String [] args ) {
17
19
Logger .getLogger (Loggers .PREFIX ).setLevel (Level .WARNING );
18
- MongoClient mongoClient = MongoClients .create (connectionString );
19
- ArrayList <Document > databases = mongoClient .listDatabases ().into (new ArrayList <>());
20
- databases .forEach (System .out :: println );
21
- mongoClient . close ();
20
+ try ( MongoClient mongoClient = MongoClients .create (PROPERTIES . getString ( "mongodb.uri" ))) {
21
+ List <Document > databases = mongoClient .listDatabases ().into (new ArrayList <>());
22
+ databases .forEach (db -> System .out . println ( db . toJson ()) );
23
+ }
22
24
}
23
25
}
Original file line number Diff line number Diff line change
1
+ package com .mongodb ;
2
+
3
+ public class HelloMongoDB {
4
+
5
+ public static void main (String [] args ) {
6
+ System .out .println ("Hello MongoDB!" );
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ mongodb.uri =YOUR MONGODB ATLAS CONNECTION STRING GOES HERE
You can’t perform that action at this time.
0 commit comments