[英]MongoDB aggregation condition translated to JAVA driver
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. 我是MongoDB的新手,我目前正在使用java进行“通过大多数标签匹配查找”解决方案来收集集合中的信息。
I'm stuck now trying to translate a MongoDB shell operation to the JAVA driver version (this sintaxis is part of the definitions needed ) 我现在试图将MongoDB shell操作转换为JAVA驱动程序版本(这个sintaxis是所需定义的一部分)
$cond:[{$eq: ["$tags", 200]}, 1, 0]
What would be a correct JAVA implementation for the sentence above? 上述句子的JAVA实现是什么?
Thank you in advance 先感谢您
Whatever the $cond object where in your aggregation operation, to build it to should do something like this: 无论$ cond对象在聚合操作中的哪个位置,要构建它应该执行以下操作:
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? 我对你的聚合操作感到困惑,你能提供更多细节吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.