Java Code Examples for com.mongodb.client.MongoCollection.listIndexes()

The following are Jave code examples for showing how to use listIndexes() of the com.mongodb.client.MongoCollection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: nifi-nars   File: AbstractMongoProcessor.java   View Source Code Vote up 5 votes
public static Set<String> getIndexNames(MongoCollection<Document> collection) {
    ListIndexesIterable<Document> currentIndexes = collection.listIndexes();
    MongoCursor<Document> cursor = currentIndexes.iterator();
    Set<String> indexNames = new HashSet<>();
    while (cursor.hasNext()) {
        Object next = cursor.next();
        String name = ((Document) next).get("name").toString();
        indexNames.add(name);
    }
    return indexNames;
}