简体   繁体   English

MongoDB Java驱动程序3.0-静态聚合函数

[英]MongoDB Java Driver 3.0 - Static functions for aggregation

I've been using MongoDB 3.0 with Java for a while now and I never had to use aggregation until now. 我已经在Java上使用MongoDB 3.0已有一段时间了,直到现在我再也不需要使用聚合。 I'm now in need of such functionality and I'm wondering why MongoDB developers didn't add any static functions for aggregation as they did for projections, filters and sorts. 我现在需要这样的功能,我想知道为什么MongoDB开发人员没有像对投影,过滤器和排序那样添加任何静态函数进行聚合。

For instance, when you want to query a document where the field docId equals 1, you can use: 例如,当您要查询字段docId等于1的文档时,可以使用:

Document document = db.getCollection("test").find(new Document("$eq", new Document("docId", 1)).first();

Or alternatively, which is awesome (providing you've imported the model.Filters class): 或者,这很棒(假设您已经导入了model.Filters类):

Document document = db.getCollection("test").find(eq("docID",1)).first();

But when it comes to aggregation, you have only the first version available: 但是,在聚合时,只有第一个可用版本:

AggregateIterable<Document> iterable = db.getCollection("test").aggregate(asList(new Document("$match", new Document("docId", 1))));

Is there any particular reason they didn't add such static functions like match, group, sort, unwind, etc.? 他们没有添加诸如match,group,sort,unwind等之类的静态函数的任何特殊原因吗? Or maybe am I so bad at googling that I haven't found it? 还是我在谷歌搜索方面很糟糕以至于没有找到它?

Thanks in advance for your explanations! 预先感谢您的解释!

Actually, after looking deeper, it happens that they just have developed these static functions and they are available in the current version (3.1-SNAPSHOT) of MongoDB Java Driver in the classes com.mongodb.client.model.Aggregates and com.mongodb.client.model.Accumulators . 实际上,在更深入地研究之后,碰巧它们只是开发了这些静态函数,并且它们在MongoDB Java驱动程序的当前版本(3.1-SNAPSHOT)中的com.mongodb.client.model.Aggregatescom.mongodb.client.model.Accumulators类中com.mongodb.client.model.Accumulators

It is not said yet when the 3.1 release is due/planned. 3.1版本的到期/计划何时还没有透露。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM