Java examples for Big Data:MongoDB
Connect to mongodb
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(); } } }