File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
source/includes/connection-snippets/x509-snippets Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ // begin x509 connection
3
+ import com .mongodb .client .MongoClient ;
4
+ import com .mongodb .client .MongoClients ;
5
+ import com .mongodb .client .MongoDatabase ;
6
+ import com .mongodb .client .MongoCollection ;
7
+ import org .bson .Document ;
8
+ import org .bson .BsonDocument ;
9
+
10
+ public class X509Connection {
11
+
12
+ public static void main (String args []) {
13
+ // Set system properties via commandline or programmatically
14
+ System .setProperty ("javax.net.ssl.keyStore" , "/etc/certs/mongodb/v3/client.keystore" );
15
+ System .setProperty ("javax.net.ssl.keyStorePassword" , "<your_password>" );
16
+
17
+ String uri = "mongodb+srv://<cluster-url>/test?authMechanism=MONGODB-X509&authSource=$external&retryWrites=true&w=majority" ;
18
+ MongoClient client = MongoClients .create (uri );
19
+ MongoDatabase database = mongoClient .getDatabase ("testDB" );
20
+ MongoCollection <Document > collection = database .getCollection ("testCol" );
21
+ BsonDocument filter = new BsonDocument ();
22
+ collection .countDocuments (filter );
23
+
24
+ client .close ();
25
+ }
26
+ }
27
+ // end x509 connection
You can’t perform that action at this time.
0 commit comments