Example usage for com.mongodb ServerAddress ServerAddress

List of usage examples for com.mongodb ServerAddress ServerAddress

Introduction

In this page you can find the example usage for com.mongodb ServerAddress ServerAddress.

Prototype

public ServerAddress(final InetSocketAddress inetSocketAddress) 

Source Link

Document

Creates a ServerAddress

Usage

From source file:testt.mongoConnector.java

public mongoConnector() throws UnknownHostException {
    /*// ww w  . j  a  va  2s  . c o  m
    *  this section won't cause any exception yet, exception will be thrown
    *  when committing update to the database        
    */
    Scanner sc = new Scanner(System.in);
    String pwd;
    System.out.print("password:");
    pwd = sc.next();

    /*char [] pwd;
    pwd = System.console().readPassword();*/
    MongoCredential mc = MongoCredential.createCredential("rwmy", "myDB", pwd.toCharArray());
    ServerAddress sa = new ServerAddress("localhost");
    client = new MongoClient(sa, Arrays.asList(mc));
    db = client.getDB("myDB");
    coll = db.getCollection("websites");
    client.setWriteConcern(WriteConcern.ACKNOWLEDGED);
}