Example usage for com.mongodb.client MongoDatabase listCollections

List of usage examples for com.mongodb.client MongoDatabase listCollections

Introduction

In this page you can find the example usage for com.mongodb.client MongoDatabase listCollections.

Prototype

ListCollectionsIterable<Document> listCollections();

Source Link

Document

Finds all the collections in this database.

Usage

From source file:com.baifendian.swordfish.common.job.struct.datasource.MongoDatasource.java

License:Apache License

@Override
public void isConnectable() throws Exception {
    MongoClient mongoClient = new MongoClient(new MongoClientURI(this.address));
    try {//from w  w  w . ja va2  s.c  o m
        MongoClientOptions options = MongoClientOptions.builder().connectTimeout(10).socketKeepAlive(false)
                .build();

        MongoDatabase db = mongoClient.getDatabase(this.database);
        for (Document doc : db.listCollections()) {
            logger.debug("{}", doc);
        }
    } finally {
        mongoClient.close();
    }
}