Example usage for com.mongodb.client MongoIterable into

List of usage examples for com.mongodb.client MongoIterable into

Introduction

In this page you can find the example usage for com.mongodb.client MongoIterable into.

Prototype

<A extends Collection<? super TResult>> A into(A target);

Source Link

Document

Iterates over all the documents, adding each to the given target.

Usage

From source file:io.lumeer.storage.mongodb.MongoUtils.java

License:Open Source License

public static List<DataDocument> convertIterableToList(MongoIterable<Document> documents) {
    final List<DataDocument> result = new ArrayList<>();
    documents.into(new ArrayList<>()).forEach(d -> result.add(MongoUtils.convertDocument(d)));

    return result;
}

From source file:net.netzgut.integral.mongo.internal.services.MongoServiceImplementation.java

License:Apache License

@Override
public void capCollection(MongoDatabase db, String collectionName, long sizeInBytes) {
    final MongoIterable<String> result = db.listCollectionNames();
    final List<String> names = result.into(new ArrayList<>());

    if (names.contains(collectionName)) {
        final Document getStats = new Document("collStats", collectionName);
        final Document stats = db.runCommand(getStats);
        Object capped = stats.get("capped");
        final boolean isCapped = capped != null && capped.equals(1);
        if (isCapped == false) {
            final Document convertToCapped = new Document();
            convertToCapped.append("convertToCapped", collectionName);
            convertToCapped.append("size", sizeInBytes);
            db.runCommand(convertToCapped);

            // We need to create the index manually after conversion.
            // See red warning box: http://docs.mongodb.org/v2.2/reference/command/convertToCapped/#dbcmd.convertToCapped
            db.getCollection(collectionName).createIndex(new Document("_id", 1));
        }/*w  w  w.  j  a  v a  2  s. co m*/
    } else {
        db.createCollection(collectionName,
                new CreateCollectionOptions().capped(true).sizeInBytes(sizeInBytes));
    }

}