當我嘗試使用大於或小於mongoDB where子句時,出現以下錯誤:任何想法如何避免這種情況?
Response message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: gt for class: Script117
下面是我的全部Groovy代碼至今: 一切正常,除了大於(或LT)查詢過濾器:
import com.mongodb.DB;
import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBCollection;
import com.mongodb.*;
//======================================================================
MongoClient mongoClient = new MongoClient(new ServerAddress("${serverIP}", ${serverPort}));
DB db = mongoClient.getDB("${mongodb}");
DBCollection coll = db.getCollection("${collectionName}");
StringBuilder rs = new StringBuilder();
rs.append("Collection: \n");
BasicDBObject allQuery = new BasicDBObject();
BasicDBObject fields = new BasicDBObject();
fields.put("name", 1); //projected fields
fields.put("age", 1); //projected fields
fields.put("eyeColor", 1); //projected fields
fields.put("balance", 1); //projected fields
BasicDBObject whereQuery = new BasicDBObject();
//whereQuery.put("gender", "female");
whereQuery.put("age", new BasicDBObject("$gt", 30));
DBCursor cursor = coll.find(whereQuery, fields);
while(cursor.hasNext()) {
DBObject obj = cursor.next();
rs.append(obj.toString());
rs.append("\n");
}
rs.toString();
//String variable at the LAST LINE of this Groovy script will be displayed in Results tab, even if no Display methods are invoked !!!