List of usage examples for com.mongodb.client MongoIterable into
<A extends Collection<? super TResult>> A into(A target);
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)); } }