将 JMeter 连接到 MongoDB Atlas

Connecting JMeter to MonogDB Atlas

MongoClientURI uri = new MongoClientURI(
"mongodb+srv://<username>:<password>cluster0-kjxf3.mongodb.net/test?retryWrites=true&w=majority");
MongoClient mongoClient = new MongoClient(uri);

ReturnsResponse message:Exception: java.lang.IllegalArgumentException: uri needs to start with mongodb://。以上URL例子来自MongoDB Atlas手册,删除+srv导致:

java.net.UnknownHostException: mongodb.net: Name or service not known

根据 Driver Examples 文档部分

To connect to an Atlas M0 (Free Tier) cluster, you must use Java version 8 or greater and use a Java driver version that supports MongoDB 3.4. For complete documentation on compatibility between the Java driver and MongoDB, see the MongoDB compatibility matrix.

所以一定要下载MongoDB Java Driver version 3.4 or higher and drop it to JMeter Classpath. You will also need to remove all previous versions of the MongoDB Driver to avoid Jar Hell。需要重新启动 JMeter 才能获取新的 .jar 并卸载旧的(如果有)

您可能还会发现 MongoDB Performance Testing with JMeter 文章很有用。