Aggregation Java Flashcards
1
Q
Which factory class should be used for building aggregation pipeline stages?
A
The Aggregates
class
2
Q
Which factory class can be used to sort data?
A
The Sorts
class
3
Q
Which factory class can be used to project data?
A
The Projections
class
4
Q
Code an example of the aggregation pipeline strucutre
A
collection.aggregate(List.of(Aggregates1, Aggregates2, ...))
5
Q
Code an example using the match stage with multiple field criteria
A
var matchStage = match(and(eq(field, value), eq(field2, value2))); collection.aggregate(List.of(matchStage));
6
Q
Code an example using the group stage
A
var groupStage = group("$groupKey", Accumulators...)); collection.aggregate(List.of(groupStage));
7
Q
Which class should you use to perform accumulator operations?
A
The Accumulators
class
8
Q
Code an example using an ascending sort and limit stage
A
var sortStage = sort(Sorts.ascending(field1, field2)); var limitStage = limit(number); collection.aggregate(List.of(sortStage, limitStage));
9
Q
Code an example of using the project stage
A
var projectStage = project(Projections...); document.aggregate(List.of(projectStage));
10
Q
Code an example using the out stage
A
var outStage = out("collectionName"); collection.aggregate(List.of(outStage));