MongoDB聚合条件已转换为JAVA驱动程序 [英] MongoDB aggregation condition translated to JAVA driver
问题描述
我对MongoDB相对较新,我目前正在与Java一起使用对大多数标签匹配进行查找解决方案来处理集合中的信息。
I'm relatively new to MongoDB and I'm currently working with java towards a "find by most tags matching" solution to information within a collection.
I现在卡住了,试图将MongoDB Shell操作转换为JAVA驱动程序版本(此sintaxis是所需定义的一部分)
I'm stuck now trying to translate a MongoDB shell operation to the JAVA driver version (this sintaxis is part of the definitions needed )
$ cond: [{$ eq:[ $ tags,200]},1,0]
对于
在此先感谢您
推荐答案
无论cond对象要在聚合操作中的哪个位置进行构建,应执行以下操作:
Whatever the $cond object where in your aggregation operation, to build it to should do something like this:
BasicDBList eqList = new BasicDBList();
eqList.add("$tags");
eqList.add(200);
DBObject eqObject = BasicDBObjectBuilder.start()
.add("$eq", eqList)
.get();
BasicDBList condList = new BasicDBList();
condList.add(eqObject);
condList.add(1);
condList.add(0);
DBObject condObject = BasicDBObjectBuilder.start()
.add("$cond", condList)
.get();
我对您的汇总操作感到困惑,能否提供更多详细信息?
I'm confusing about your aggregation operation, could you give more details?
这篇关于MongoDB聚合条件已转换为JAVA驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!