Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import com.mongodb.DB;
import com.mongodb.MongoClient;

public class Main {
    public static void main(String args[]) {
        try {
            MongoClient mongoClient = new MongoClient("localhost", 27017);

            DB db = mongoClient.getDB("test");
            System.out.println("Connect to database successfully");
            boolean auth = db.authenticate("myUser", "myPassword".toCharArray());
            System.out.println("Authentication: " + auth);
        } catch (Exception e) {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
    }
}