Monday, June 13, 2016

Run MongoDB as a service

Following command can be used to run mongo db as service.

mongod.exe --install --dbpath "c:\mongo\data\db" --logpath "c:\mongo\data\log"

You can also set dbpath & logpath in "mongod.cfg" file and run the command as follows.

mongod.exe --install --config "c:\mongo\mongod.cfg"

Sample mongod.cfg

    destination: file
    path: C:\Program Files\MongoDB\Server\3.2\data\log\mongod.log
    dbPath: C:\Program Files\MongoDB\Server\3.2\data\db

In Windows, you can stop service in services management window. Run/Services

In Linux, ps -ef|grep mongo then kill -9 process_id

Tuesday, June 7, 2016

Trust certificates in JAVA

Following trust manager can be used to ignore validation certificate chains.

TrustManager[] trustAllCerts = new TrustManager[] {
    new X509TrustManager() {
        public[] getAcceptedIssuers() {
            return null;
        public void checkClientTrusted(
  [] certs, String authType) {
        public void checkServerTrusted(
  [] certs, String authType) {

// Install the all-trusting trust manager
try {
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new;
} catch (GeneralSecurityException e) {