Last active
July 31, 2020 23:31
-
-
Save kommradHomer/e38007f8f03fcd2f792c8acbf7b75da3 to your computer and use it in GitHub Desktop.
bucket used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bson a=Aggregates.match( new Document("year", 5)); | |
BucketOptions o=new BucketOptions(); | |
o.output( | |
new BsonField("student_ids", new Document("$push","$student_id")), | |
new BsonField("attended_class",new Document("$sum", | |
new Document("$cond", | |
Arrays.asList( | |
new Document("$gte",Arrays.asList("$attn",8)), | |
1, | |
0 | |
) | |
) | |
) | |
), | |
new BsonField("students_total", new Document("$sum",1)) | |
); | |
Bson b=Aggregates.bucket("$final_grade", Arrays.asList(0,45,55,70,85,100),o); | |
//LIST for the pipeline | |
List<Bson> l=new ArrayList<>(); | |
l.add(a); | |
l.add(b); | |
//STUDENTS_COLLECTION mongodb collection assumed to be provided | |
MongoCursor cur=STUDENTS_COLLECTION.aggregate(l).iterator(); | |
//print as JSON | |
while(cur.hasNext()) | |
System.out.println(((Document) cur.next()).toJson()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment