Last active
December 24, 2015 16:29
-
-
Save mhelmstetter/6828936 to your computer and use it in GitHub Desktop.
Sample Java application connecting to MongoDB via SSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.net.ssl.SSLSocketFactory; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.MongoClient; | |
import com.mongodb.MongoClientOptions; | |
public class SSLApp { | |
public static void main(String args[]) throws Exception { | |
MongoClientOptions o = new MongoClientOptions.Builder() | |
.socketFactory(SSLSocketFactory.getDefault()) | |
.build(); | |
MongoClient m = new MongoClient("localhost", o); | |
DB db = m.getDB( "test" ); | |
DBCollection c = db.getCollection( "foo" ); | |
c.insert(new BasicDBObject("testKey", "testValue")); | |
System.out.println( c.findOne() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment