什么是AggregationOutput在mongoDB中执行查找操作的替代方法

时间:2018-12-12 14:39:43

标签: mongodb groovy jmeter

收藏 = c_1,c_2
我想在mongodb中使用 groovy语言执行查找操作。我成功创建了匹配,查找和项目操作。但是我在 AggregationOutput 中遇到错误。

c_1.insert(new BasicDBObject(["id" : 1, "name" : "abc", "lastName" : "kumar",  "companyId": 10]))  
c_2.insert(new BasicDBObject(["id" : 10, "companyName" : "Microsoft", "numEmployee" : 100 ]))  
// Successfully created the $match operations
// Successfully created the $lookup operations  
// Successfully created the $project operations  
List<DBObject> pipeline = Arrays.asList(match, lookup, project);  
AggregationOutput output = c_1.aggregate(pipeline);  

错误:响应消息:javax.script.ScriptException:java.lang.IllegalArgumentException:参数数量错误

1 个答案:

答案 0 :(得分:1)

根据DBCollection JavaDoc

public AggregationOutput aggregate(DBObject firstOp,
                      DBObject... additionalOps)

您无法将List传递给该函数,您需要执行以下操作:

AggregationOutput output = c_1.aggregate(pipeline.get(0), pipeline.get(1), pipeline.get(2));

查看How to Load Test MongoDB with JMeter文章,以了解有关使用JMeter进行MongoDB负载测试的更多信息。