本文整理汇总了Java中com.mongodb.client.model.Aggregates类的典型用法代码示例。如果您正苦于以下问题:Java Aggregates类的具体用法?Java Aggregates怎么用?Java Aggregates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Aggregates类属于com.mongodb.client.model包,在下文中一共展示了Aggregates类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getGardenLocationsAsJson
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
/**
* Takes `uploadID` and returns all bed names as a json format string
* @param uploadID - the year that the data was uploaded
* @return String representation of json with all bed names
*/
public String getGardenLocationsAsJson(String uploadID){
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadID", uploadID)), //!! Order is important here
Aggregates.group("$gardenLocation"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<Document> listDoc = new ArrayList<>();
for (Document doc : documents) {
listDoc.add(doc);
}
listDoc.sort(new BedComparator());
return JSON.serialize(listDoc);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:23,代码来源:PlantController.java
示例2: averageAge
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
@Test
public void averageAge() {
AggregateIterable<Document> documents
= userDocuments.aggregate(
Arrays.asList(
Aggregates.group("$company",
Accumulators.avg("averageAge", "$age")),
Aggregates.sort(Sorts.ascending("_id"))
));
List<Document> docs = intoList(documents);
assertEquals("Should be three companies", 3, docs.size());
assertEquals("Frogs, Inc.", docs.get(0).get("_id"));
assertEquals(37.0, docs.get(0).get("averageAge"));
assertEquals("IBM", docs.get(1).get("_id"));
assertEquals(37.0, docs.get(1).get("averageAge"));
assertEquals("UMM", docs.get(2).get("_id"));
assertEquals(25.0, docs.get(2).get("averageAge"));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:20,代码来源:MongoSpec.java
示例3: listUploadIds
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
/**
*
* @return a date-sorted List of all the distinct uploadIds in the DB
*/
public static List<String> listUploadIds(MongoDatabase database) {
MongoCollection<Document> plantCollection = database.getCollection("plants");
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.group("$uploadId"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<String> lst = new LinkedList<>();
for(Document d: documents) {
lst.add(d.getString("_id"));
}
return lst;
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:20,代码来源:ExcelParser.java
示例4: returnValueToURL
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public int returnValueToURL(String URL)
{
Block<Document> printBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document.toJson());
}
};
MongoCollection<Document> collection = db.getCollection("ratings");
collection.aggregate(
Arrays.asList(
Aggregates.group("URL", Accumulators.avg("rating", 1))))
.forEach(printBlock);
System.out.println(printBlock.toString());
return 0;
}
开发者ID:Sigma-News,项目名称:Backend,代码行数:18,代码来源:MongoDBManager.java
示例5: getServerQuery
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
private static List<Bson> getServerQuery(Bson filter) {
final List<Bson> pipeline = new ArrayList<>(6);
if (filter != ALL) {
pipeline.add(Aggregates.match(filter));
}
pipeline.add(Aggregates.unwind("$deployments", new UnwindOptions().preserveNullAndEmptyArrays(true)));
pipeline.add(Aggregates.lookup(Collections.APPLICATIONS, "deployments.applicationId", "id", "applications"));
pipeline.add(Aggregates.unwind("$applications", new UnwindOptions().preserveNullAndEmptyArrays(true)));
pipeline.add(Aggregates.group(
new Document().append("hostname", "$hostname").append("environment", "$environment"),
new BsonField("fqdn", new Document("$first", "$fqdn")),
new BsonField("description", new Document("$first", "$description")),
new BsonField("os", new Document("$first", "$os")),
new BsonField("network", new Document("$first", "$network")),
new BsonField("meta", new Document("$first", "$meta")),
new BsonField("attributes", new Document("$first", "$attributes")),
new BsonField("applications", new Document("$push", "$applications")),
new BsonField("deployments", new Document("$push", "$deployments"))));
pipeline.add(Aggregates.sort(Sorts.ascending("_id")));
return pipeline;
}
开发者ID:atgse,项目名称:sam,代码行数:23,代码来源:ServerResource.java
示例6: ageCounts
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
@Test
public void ageCounts() {
AggregateIterable<Document> documents
= userDocuments.aggregate(
Arrays.asList(
/*
* Groups data by the "age" field, and then counts
* the number of documents with each given age.
* This creates a new "constructed document" that
* has "age" as it's "_id", and the count as the
* "ageCount" field.
*/
Aggregates.group("$age",
Accumulators.sum("ageCount", 1)),
Aggregates.sort(Sorts.ascending("_id"))
)
);
List<Document> docs = intoList(documents);
assertEquals("Should be two distinct ages", 2, docs.size());
assertEquals(docs.get(0).get("_id"), 25);
assertEquals(docs.get(0).get("ageCount"), 1);
assertEquals(docs.get(1).get("_id"), 37);
assertEquals(docs.get(1).get("ageCount"), 2);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:25,代码来源:MongoSpec.java
示例7: getCommonNamesJSON
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
/**
* Get a json containing a list of commonNames sorted by common name
* @param uploadID
* @return
*/
public String getCommonNamesJSON(String uploadID){
if (!ExcelParser.isValidUploadId(db, uploadID))
return "null";
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadId", uploadID)), //!! Order is important here
Aggregates.group("$commonName"),
Aggregates.sort(Sorts.ascending("commonName"))
));
return JSON.serialize(documents);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-revolverenguardia-1,代码行数:19,代码来源:PlantController.java
示例8: getGardenLocationsAsJson
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public String getGardenLocationsAsJson(String uploadID) {
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.match(eq("uploadId", uploadID)), //!! Order is important here
Aggregates.group("$gardenLocation"),
Aggregates.sort(Sorts.ascending("_id"))
));
return JSON.serialize(documents);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:11,代码来源:PlantController.java
示例9: listUploadIds
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
/**
*
* @return a sorted JSON array of all the distinct uploadIds in the DB
*/
public String listUploadIds() {
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.group("$uploadId"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<String> lst = new LinkedList<>();
for(Document d: documents) {
lst.add(d.getString("_id"));
}
return JSON.serialize(lst);
// return JSON.serialize(plantCollection.distinct("uploadId","".getClass()));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:19,代码来源:PlantController.java
示例10: listUploadIDs
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
/**
*
* @return a sorted JSON array of all the distinct uploadIDs in plant collection of the DB
*/
public List<String> listUploadIDs() {
AggregateIterable<Document> documents
= plantCollection.aggregate(
Arrays.asList(
Aggregates.group("$uploadID"),
Aggregates.sort(Sorts.ascending("_id"))
));
List<String> lst = new LinkedList<>();
for(Document d: documents) {
lst.add(d.getString("_id"));
}
return lst;
// return JSON.serialize(plantCollection.distinct("uploadID","".getClass()));
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:19,代码来源:PlantController.java
示例11: getNodeDetails
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public List<SyncNodeDetails> getNodeDetails(String lifeCycle) {
UnwindOptions options = new UnwindOptions();
options.preserveNullAndEmptyArrays(true);
Document group = new Document("$group",
new Document(SyncAttrs.ID, new Document("_id", "$_id").append("host","$host").append("node","$node").append("state","$state")
.append("concurrencyLevel","$concurrencyLevel").append("totalHeapSize", "$totalHeapSize")
.append("usedHeapSize", "$usedHeapSize").append("lifeCycle", "$lifeCycle"))
.append("eventArr", new Document("$addToSet", "$event_docs")));
return migrationNodeMapping.aggregate(Arrays.asList(Aggregates.match(Filters.eq(SyncAttrs.LIFE_CYCLE,lifeCycle)),
Aggregates.unwind("$activeEvents",options),
Aggregates.lookup("SyncEvents", "activeEvents", "_id", "event_docs"),
Aggregates.unwind("$event_docs", options),
group,Aggregates.project(new Document("node", "$_id").append("events","$eventArr").append("_id", false))), SyncNodeDetails.class)
.into(new ArrayList<SyncNodeDetails>());
}
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:16,代码来源:SyncNodeDetailsDao.java
示例12: getEventStats
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public SyncMarker getEventStats(ObjectId eventId) {
Document group = new Document("$group",
new Document(SyncAttrs.ID, null).append(SyncAttrs.TOTAL_ROWS, new Document("$sum", "$marker.totalRows"))
.append(SyncAttrs.ROWS_READ, new Document("$sum", "$marker.rowsRead"))
.append(SyncAttrs.ROWS_DUMPED, new Document("$sum", "$marker.rowsDumped"))
.append(SyncAttrs.START_TIME, new Document("$min", "$marker.startTime"))
.append(SyncAttrs.END_TIME, new Document("$max", "$marker.endTime")));
return syncEvents.aggregate(Arrays.asList(Aggregates.match(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId)),
Aggregates.project(Projections.include(SyncAttrs.MARKER)), group), SyncMarker.class).first();
}
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:11,代码来源:SyncEventDao.java
示例13: getEventErrors
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public List<SyncError> getEventErrors(ObjectId eventId) {
Document group = new Document("$group",
new Document(SyncAttrs.ID, null).append(SyncAttrs.ERRORS, new Document("$addToSet", "$errors")));
return syncEvents.aggregate(
Arrays.asList(Aggregates.match(Filters.eq(SyncAttrs.PARENT_EVENT_ID, eventId)),
Aggregates.unwind("$errors"),
Aggregates
.project(Projections.include(SyncAttrs.ERRORS)),
group, Aggregates.unwind("$errors"),
Aggregates.project(new Document(SyncAttrs.ERROR_MESSAGE, "$errors.errorMessage")
.append(SyncAttrs.TRACE, "$errors.trace")
.append(SyncAttrs.THREAD_NAME, "$errors.threadName"))),
SyncError.class).allowDiskUse(true).into(new ArrayList<SyncError>());
}
开发者ID:gagoyal01,项目名称:mongodb-rdbms-sync,代码行数:15,代码来源:SyncEventDao.java
示例14: getAverageAgeByCompany
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
public String getAverageAgeByCompany() {
AggregateIterable<Document> documents
= userCollection.aggregate(
Arrays.asList(
Aggregates.group("$company",
Accumulators.avg("averageAge", "$age")),
Aggregates.sort(Sorts.ascending("_id"))
));
System.err.println(JSON.serialize(documents));
return JSON.serialize(documents);
}
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:12,代码来源:UserController.java
示例15: testAggregate
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
@Test
public void testAggregate()
{
List<Document> docList = new ArrayList<Document>();
coll.aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
Aggregates.group("color", Accumulators.sum("count", 1)))).into(docList);
assertEquals(1, docList.size());
docList.clear();
Document first = coll
.aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
Aggregates.group("color", Accumulators.sum("count", 1))), Document.class)
.allowDiskUse(true).batchSize(12).bypassDocumentValidation(true).collation(Collation.builder().build())
.first();
Assert.assertNotNull(first);
first = coll
.aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
Aggregates.group("color", Accumulators.sum("count", 1))), Document.class)
.allowDiskUse(true).batchSize(12).bypassDocumentValidation(true).collation(Collation.builder().build())
.map(new Function<Document, Document>()
{
@Override
public Document apply(Document t)
{
t.put("hello", "world");
return t;
}
}).first();
Assert.assertNotNull(first);
}
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:35,代码来源:ProfiledMongoClientTest.java
示例16: testFilterParametersBsonDocumentMatchInAndEq
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
@Test
public void testFilterParametersBsonDocumentMatchInAndEq()
{
Bson in = Filters.in("dateKey", "593898622313868b72a296ad", "593898622313868b72a296b4");
Bson eq = Filters.eq("eqfield","123");
Bson and = Filters.and(in, eq);
Bson match = Aggregates.match(and);
BsonDocument filterParameters = MongoUtilities.filterParameters(match);
assertEquals("{ \"$match\" : { \"dateKey\" : { \"$in\" : [\"*?\"] }, \"eqfield\" : \"?\" } }", filterParameters.toString());
}
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:15,代码来源:MongoUtilitiesTest.java
示例17: testFilterParametersBsonDocumentMatchInOrEq
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
@Test
public void testFilterParametersBsonDocumentMatchInOrEq()
{
Bson in = Filters.in("dateKey", "593898622313868b72a296ad", "593898622313868b72a296b4");
Bson eq = Filters.eq("eqfield","123");
Bson or = Filters.or(in, eq);
Bson match = Aggregates.match(or);
BsonDocument filterParameters = MongoUtilities.filterParameters(match);
assertEquals("{ \"$match\" : { \"$or\" : [{ \"dateKey\" : { \"$in\" : [\"*?\"] } }, { \"eqfield\" : \"?\" }] } }", filterParameters.toString());
}
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:15,代码来源:MongoUtilitiesTest.java
示例18: findApplications
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
private PaginatedCollection<Application> findApplications(Bson filter) {
final List<Bson> pipeline = new ArrayList<>(2);
if (filter != ALL) {
pipeline.add(Aggregates.match(filter));
}
pipeline.add(Aggregates.lookup(Collections.GROUPS, "group", "id", "group"));
return RestHelper.paginatedList(database
.getCollection(Collections.APPLICATIONS)
.aggregate(pipeline)
.map(Application::new)
);
}
开发者ID:atgse,项目名称:sam,代码行数:15,代码来源:ApplicationResource.java
示例19: findApplication
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
private Document findApplication(Bson filter) {
final Document bson = database.getCollection(Collections.APPLICATIONS)
.aggregate(Lists.newArrayList(
Aggregates.match(filter),
Aggregates.lookup(Collections.GROUPS, "group", "id", "group")
)).first();
if (bson == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
return bson;
}
开发者ID:atgse,项目名称:sam,代码行数:12,代码来源:ApplicationResource.java
示例20: getAllGroups
import com.mongodb.client.model.Aggregates; //导入依赖的package包/类
private Map<String,Group> getAllGroups() {
return Maps.uniqueIndex(database
.getCollection(Collections.GROUPS)
.aggregate(Lists.newArrayList(
Aggregates.lookup(Collections.APPLICATIONS, "id", "group", "applications"),
Aggregates.lookup(Collections.ASSETS, "id", "group", "assets")
)).map(Group::new),
t->t.id
);
}
开发者ID:atgse,项目名称:sam,代码行数:11,代码来源:GroupResource.java
注:本文中的com.mongodb.client.model.Aggregates类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论