Mongo Ruby shards now available

If you have already imported the certificate then you can also use the below code (much simpler version).

import com.mongodb.*;

import javax.net.ssl.SSLSocketFactory;

 

public class SSLApp1 {

 

    public static void main(String args[])  throws Exception {

 

         System.setProperty(“javax.net.ssl.trustStore”,

                “C:\\Program Files\\Java\\jre7\\lib\\security\\cacerts”);

 

        MongoClientOptions o = new MongoClientOptions.Builder()

                .socketFactory(SSLSocketFactory.getDefault())

                .build();

 

        MongoClient m = new MongoClient(“<server>:<port>”, o);  

 

        System.out.println(“Host:” + m.getServerAddressList());

 

        DB db = m.getDB( “admin” );

        System.out.println(“DB: [” + db + “]”);

 

        boolean auth = db.authenticate(<user>, <pwd>.toCharArray());

        System.out.println(“auth: [” + auth + “]”);

 

        com.mongodb.DB db1 = m.getDB(“admin”);

        System.out.println(“Using .command”);

        DBObject cmd1 = new BasicDBObject();

        cmd1.put(“listDatabases”,”1″);

        CommandResult result = db1.command(cmd1);

        System.out.println(result.toString());

 

    

  • Ask Question