首页 > 解决方案 > 如何使用groovy在JMeter上调用MongoDB查询的计数操作?

问题描述

我有一个查询如下,它正在使用 mongoDB

我需要在 JMeter 中执行此查询以获取对象计数。请注意,我正在使用 Groovy 脚本来执行相同的操作。

db.getCollection('collectionName').find({ $or: [ {"Service" :"AAA"}, {ServerName : "BBB"} ],
   "ConnectionID" : "AAAA445789",
       "CDDval" : "AGB"
});

Below is the code i am running in groovy and not giving the expected result like Mongodb query above.it is giving error javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:


try {
    MongoCollection<Document> collection = vars.getObject("collectionName");

     Document result = collection.find("uuid" ,"{$or : [

    {"Service": "AAA"},
    {ServerName : "BBB"}    
    ],

     "ConnectionID" : "AAAA445789",
     "CDDval" : "AGB"


     "}).first;


     vars.put("uuid", result.get("uuid").toString());

     return "uuid=" + result.get("uuid") + " found";

}
catch (Exception e) {
    SampleResult.setSuccessful(false);
    SampleResult.setResponseCode("500");
    SampleResult.setResponseMessage("Exception: " + e);
}

I have tried the using JMeter Groovy 2.4.13 but not getting correct respose, below is the code


标签: mongodbgroovyjmeter

解决方案


推荐阅读