Latest commit 05d983e Oct 11, 2018
Failed to load latest commit information.
src Resync CRUD specification tests Oct 11, 2018 Count API updates Jun 18, 2018
build.gradle Build: Packaging for driver-embedded projects Oct 9, 2018

The MongoDB Asynchronous Java Driver

A callback-based fully non-blocking and asynchronous I/O operations MongoDB Java driver.


Binaries and dependency information for Maven, Gradle, Ivy and others can be found at

Example for Maven:


Snapshot builds are also published regulary via Sonatype.

Example for Maven:


Usage example:

    import com.mongodb.Block;
    import com.mongodb.ConnectionString;
    import com.mongodb.async.SingleResultCallback;
    import com.mongodb.async.client.MongoClient;
    import com.mongodb.async.client.MongoClients;
    import com.mongodb.async.client.MongoCollection;
    import com.mongodb.async.client.MongoDatabase;
    import org.bson.Document;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.concurrent.CountDownLatch;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.TimeUnit;
    import java.util.concurrent.atomic.AtomicLong;

    // Open the client
    MongoClient mongoClient = MongoClients.create(new ConnectionString("mongodb://localhost:27017"));

    // Print out all databases
    final CountDownLatch listDbsLatch = new CountDownLatch(1);
    System.out.println("Outputting database names:");
    mongoClient.listDatabaseNames().forEach(new Block<String>() {
        public void apply(final String name) {
            System.out.println(" - " + name);
    }, new SingleResultCallback<Void>() {
        public void onResult(final Void result, final Throwable t) {
    boolean listedAllDbs = listDbsLatch.await(1, TimeUnit.SECONDS);

    // get handle to "mydb" database
    final MongoDatabase database = mongoClient.getDatabase("mydb");

    // Get handle to "test" collection
    final MongoCollection<Document> collection = database.getCollection("test");

    // Drop the collection and insert 100 documents
    final CountDownLatch insertLatch = new CountDownLatch(1);
    System.out.println("Dropping collection and inserting documents");
    collection.dropCollection(new SingleResultCallback<Void>() {
        public void onResult(final Void result, final Throwable t) {
            System.out.println(" - collection dropped");
            // now, lets add lots of little documents to the collection so we can explore queries and cursors
            List<Document> documents = new ArrayList<Document>();
            for (int i = 0; i < 100; i++) {
                documents.add(new Document("i", i));
            collection.insertMany(documents, new SingleResultCallback<Void>() {
                public void onResult(final Void result, final Throwable t) {
                    System.out.println(" - documents inserted");

    boolean inserted = insertLatch.await(10, TimeUnit.SECONDS);

    // Count should now be 100
    final CountDownLatch countLatch = new CountDownLatch(1);
    final AtomicLong count = new AtomicLong();
    System.out.println("Counting the number of documents");
    collection.countDocuments(new SingleResultCallback<Long>() {
        public void onResult(final Long result, final Throwable t) {
    boolean counted = countLatch.await(1, TimeUnit.SECONDS);
    System.out.println(" - Count result: " + count.get());

    // release resources