Connect to mongodb - Java Big Data

Java examples for Big Data:MongoDB

Description

Connect to mongodb

Demo Code



import com.mongodb.MongoClient;
import com.mongodb.client.MongoDatabase;

public class Mongodb {

  public static void main(String[] args) {
    try {/*from www .j ava2s.c o m*/
      MongoClient mongoClient = new MongoClient("localhost");  
      MongoDatabase mongoDatabase = mongoClient.getDatabase("mycol");
      System.out.println("Connect to database successfully");
      

    } catch (Exception e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
        e.printStackTrace();
    }
  }

}

Related Tutorials