JMETER - MongoDB 删除 jmeter 的记录示例脚本

JMETER - MongoDB delete record sample script for jmeter

有人可以帮助我 groovy 从 MongoDB 集合中删除记录的示例代码吗?提前致谢。

在删除一个对象之前,您需要找到一个。

完整示例代码(我希望您只对最后一行感兴趣,但以防万一):

import com.mongodb.*  // import all the mongodb.* stuff
import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;


DB db = MongoDBHolder.getDBFromSource("MongoDBSourceName", "DatabaseName");
DBCollection collection = db.getCollection("CollectionName");

BasicDBObject query = new BasicDBObject("name", "value"); // create DBObject holding the query
DBObject result = collection.findOne(query); // find the document

collection.remove(result); //delete the document

参考文献: