if (batch) {
DBObject[] arr = new BasicDBObject[n];
for (int i = 0; i < n; i++) {
arr[i] = new BasicDBObject("_path", "/a" + i);
}
WriteResult result = collection.insert(arr);
if (result.getError() != null) {
log("Error: " + result.getError());
}
} else {
for (int i = 0; i < n; i++) {
WriteResult result = collection.insert(new BasicDBObject("_path", "/a" + i));
if (result.getError() != null) {
log("Error: " + result.getError());
}
}
}