本文整理匯總了Java中com.mongodb.client.FindIterable.forEach方法的典型用法代碼示例。如果您正苦於以下問題:Java FindIterable.forEach方法的具體用法?Java FindIterable.forEach怎麽用?Java FindIterable.forEach使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mongodb.client.FindIterable
的用法示例。
在下文中一共展示了FindIterable.forEach方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findReportsRaw
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
public static JSONObject findReportsRaw() {
JSONArray reports = new JSONArray();
FindIterable<Document> result = findReports();
result.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
JSONObject jsonReport = new JSONObject();
jsonReport.put("id", document.getObjectId("_id").toString());
jsonReport.put("comment", document.getString("comment"));
jsonReport.put("city_item_id", document.getString("city_item_id"));
jsonReport.put("priority", document.getInteger("priority"));
jsonReport.put("resolved", document.getBoolean("resolved"));
jsonReport.put("report_date", document.getLong("report_date"));
reports.put(jsonReport);
}
});
JSONObject jsonResults = new JSONObject();
jsonResults.put("reports", reports);
return jsonResults;
}
示例2: findReportsForView
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
/**
* Returns all reports for view
*
* @return List
*/
public static List<ReportViewObject> findReportsForView() {
List<ReportViewObject> reports = new ArrayList<>();
FindIterable<Document> result = findReports();
result.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
Report.Builder b = new Report.Builder();
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String reportDate = df.format(new Date(document.getLong("report_date")));
reports.add(new ReportViewObject(
document.getObjectId("_id").toString(),
Integer.toString(document.getInteger("priority")),
document.getString("city_item_id"),
reportDate,
document.getBoolean("resolved") ? "YES" : "NO"));
}
});
return reports;
}
示例3: run
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public void run() {
System.out.println("Reader started");
MongoCollection<Document> collection = DBCacheManager.INSTANCE.getCachedMongoPool(mongoDbName, mongoUserName)
.getDatabase(mongoDbName).getCollection(collectionName);
FindIterable<Document> it = collection.find().batchSize(batchSize);
it.forEach(new Block<Document>() {
@Override
public void apply(Document t) {
System.out.println("Document read " + t);
try {
dataBuffer.put(t);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
示例4: findByCategory
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public List<SurveyActivity> findByCategory(String categoryName) {
ArrayList<SurveyActivity> activities = new ArrayList<>();
FindIterable<Document> result = collection.find(eq("category.name", categoryName));
result.forEach((Block<Document>) document -> activities.add(SurveyActivity.deserialize(document.toJson())));
return activities;
}
示例5: search
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public synchronized List<Karma> search(String queryString) {
int order = DESC;
List<Karma> result = new ArrayList<>();
BasicDBObject query = new BasicDBObject();
queryString = queryString.toLowerCase();
if (queryString.startsWith("!")) {
queryString = queryString.substring(1);
order = ASC;
}
if (queryString.contains("*")) {
query.put("_id", new BasicDBObject("$regex", queryString.replace("*", ".*")).append("$options", "i"));
} else {
query.put("_id", queryString);
}
FindIterable<Document> documents = karmas.find(query).sort(new BasicDBObject().append("value", order)).limit(10);
documents.forEach((Consumer<Document>) document -> result.add(gson.fromJson(document.toJson(), Karma.class)));
return result;
}
示例6: fireEvent
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
/**
* Fires an event on all objects in the cache, which fulfill the query
*
* @param event
* @param query
*/
public void fireEvent(final DataEvent event, BaseQuery query) {
//query only ids
FindIterable cursor = collection.find(query.getQuery());
cursor.forEach(new Block() {
@Override
public void apply(Object t) {
org.bson.Document dbObject = (org.bson.Document) t;
String id = "" + dbObject.get("_id");
synchronized (map) {
Document o = map.get(id);
if (o != null) {
o.fireChangedEvent(event);
}
}
}
});
}
示例7: main
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
public static void main(String[] args) {
// new client
MongoClient client = new MongoClient();
// get the data base
MongoDatabase db = client.getDatabase("other");
// here create a new collection
//db.createCollection("filestore");
// insert data into the collection
db.getCollection("filestore").insertOne(
new Document()
.append("name", "smile")
.append("age", 20));
// retrive the data
FindIterable<Document> iterable = db.getCollection("filestore").find();
// show data
iterable.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document);
}
});
}
示例8: main
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
public static void main(String[] args) {
// new client
MongoClient client = new MongoClient();
// get the data base
MongoDatabase db = client.getDatabase("other");
// here create a new collection
//db.createCollection("filestore");
// insert data into the collection
db.getCollection("filestore").insertOne(
new Document()
.append("name", "smile")
.append("age", 20));
// retrive the data
FindIterable<Document> iterable = db.getCollection("filestore").find();
// show data
iterable.forEach(new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document);
}
});
}
示例9: processEventLogFlow
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
private void processEventLogFlow() throws InterruptedException {
FindIterable<O2MSyncEventLog> it = getCursor();
retryCount = 0;
it.forEach(new Block<O2MSyncEventLog>() {
@Override
public void apply(O2MSyncEventLog eventLog) {
try {
if (marker.isFailed()) {
releaseReources();
return;
}
logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.RUNNING));
logger.info("Processing filter : "+eventLog.getEventFilters());
if (eventLog.getOperation().equals(SyncConstants.DELETE)) {
processDeletedDoc(eventLog);
}else{
processMongoObject(map.getMapObject(), true, null, map.getMapObject().getCollectionName(),
eventLog);
}
logCollection.findOneAndUpdate(Filters.eq(SyncAttrs.ID, eventLog.getLogId()),
Updates.set(O2MSyncEventLogCodec.STATUS, O2MSyncEventLogCodec.COMPLETE));
logger.info("Processed filter : "+eventLog.getEventFilters());
} catch (SyncError e) {
logger.error("Error in O2M replication", e);
Mailer.sendmail(eventId, null, e, Mailer.FAILURE);
}
}
});
}
示例10: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public List<DataSource> find() {
ArrayList<DataSource> dataSources = new ArrayList<DataSource>();
FindIterable<Document> result = collection.find();
result.forEach((Block<Document>) document -> {
dataSources.add(DataSource.deserialize(document.toJson()));
});
return dataSources;
}
示例11: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
/**
* Return activities considering that they were not discarded
* @param rn
* @return
*/
@Override
public List<SurveyActivity> find(long rn) {
ArrayList<SurveyActivity> activities = new ArrayList<SurveyActivity>();
FindIterable<Document> result = collection.find(and(eq("participantData.recruitmentNumber", rn), eq("isDiscarded", false)));
result.forEach((Block<Document>) document -> {
activities.add(SurveyActivity.deserialize(document.toJson()));
});
return activities;
}
示例12: findNonDeleted
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public List<ActivityCategory> findNonDeleted() {
ArrayList<ActivityCategory> categories = new ArrayList<>();
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("disabled", false);
FindIterable<Document> documents = collection.find(query);
documents.forEach((Block<? super Document>) document -> categories.add(ActivityCategory.deserialize(document.toJson())));
return categories;
}
示例13: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public List<ExamLot> find() {
ArrayList<ExamLot> ExamLots = new ArrayList<>();
FindIterable<Document> result = collection.find();
result.forEach((Block<Document>) document -> ExamLots.add(ExamLot.deserialize(document.toJson())));
return ExamLots;
}
示例14: find
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public List<TransportationLot> find() {
ArrayList<TransportationLot> transportationLots = new ArrayList<>();
FindIterable<Document> result = collection.find();
result.forEach((Block<Document>) document -> transportationLots.add(TransportationLot.deserialize(document.toJson())));
return transportationLots;
}
示例15: getFullAliquotsList
import com.mongodb.client.FindIterable; //導入方法依賴的package包/類
@Override
public ArrayList<Aliquot> getFullAliquotsList() {
ArrayList<Aliquot> fullList = new ArrayList<Aliquot>();
FindIterable<Document> list = collection.find();
list.forEach((Block<Document>) document ->{
ParticipantLaboratory laboratory = ParticipantLaboratory.deserialize(document.toJson());
fullList.addAll(laboratory.getAliquotsList());
});
return fullList;
}